Skip to content

Commit c96c96b

Browse files
committed
fix: preserve error cause in getHostAddress() for better debugging
The getHostAddress() method in DurableTaskAzureManagedClientOptions drops the original URL parsing error when re-throwing, making it difficult to debug why a specific endpoint URL is invalid. This change preserves the original error as the cause property of the new Error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9d5bbc3 commit c96c96b

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/durabletask-js-azuremanaged/src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ abstract class DurableTaskAzureManagedOptionsBase {
101101
authority = `${authority}:${url.port}`;
102102
}
103103
return authority;
104-
} catch {
105-
throw new Error(`Invalid endpoint URL: ${endpoint}`);
104+
} catch (e) {
105+
throw new Error(`Invalid endpoint URL: ${endpoint}`, { cause: e });
106106
}
107107
}
108108

packages/durabletask-js-azuremanaged/test/unit/options.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ describe("Options", () => {
158158

159159
expect(() => options.getHostAddress()).toThrow("Invalid endpoint URL:");
160160
});
161+
162+
it("should preserve the original error as cause when URL parsing fails", () => {
163+
const options = new DurableTaskAzureManagedClientOptions().setEndpointAddress("invalid:url");
164+
165+
try {
166+
options.getHostAddress();
167+
fail("Expected getHostAddress to throw");
168+
} catch (e: unknown) {
169+
expect(e).toBeInstanceOf(Error);
170+
const error = e as Error;
171+
expect(error.message).toContain("Invalid endpoint URL:");
172+
expect(error.cause).toBeDefined();
173+
// The cause should be the original URL parsing error
174+
expect((error.cause as Error).message).toBeDefined();
175+
expect((error.cause as Error).message.length).toBeGreaterThan(0);
176+
}
177+
});
161178
});
162179

163180
describe("createChannelCredentials", () => {

0 commit comments

Comments
 (0)