Skip to content

Commit d63d91e

Browse files
authored
fix: preserve error cause in getHostAddress() for better debugging (#194)
1 parent 8d59848 commit d63d91e

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)