From c96c96b61ac76b0ca78b36e8981089b924662fba Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 08:37:08 +0000 Subject: [PATCH] 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> --- .../durabletask-js-azuremanaged/src/options.ts | 4 ++-- .../test/unit/options.spec.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/durabletask-js-azuremanaged/src/options.ts b/packages/durabletask-js-azuremanaged/src/options.ts index 30f9c556..e60279ba 100644 --- a/packages/durabletask-js-azuremanaged/src/options.ts +++ b/packages/durabletask-js-azuremanaged/src/options.ts @@ -101,8 +101,8 @@ abstract class DurableTaskAzureManagedOptionsBase { authority = `${authority}:${url.port}`; } return authority; - } catch { - throw new Error(`Invalid endpoint URL: ${endpoint}`); + } catch (e) { + throw new Error(`Invalid endpoint URL: ${endpoint}`, { cause: e }); } } diff --git a/packages/durabletask-js-azuremanaged/test/unit/options.spec.ts b/packages/durabletask-js-azuremanaged/test/unit/options.spec.ts index d0f6c7cb..90b20b6f 100644 --- a/packages/durabletask-js-azuremanaged/test/unit/options.spec.ts +++ b/packages/durabletask-js-azuremanaged/test/unit/options.spec.ts @@ -158,6 +158,23 @@ describe("Options", () => { expect(() => options.getHostAddress()).toThrow("Invalid endpoint URL:"); }); + + it("should preserve the original error as cause when URL parsing fails", () => { + const options = new DurableTaskAzureManagedClientOptions().setEndpointAddress("invalid:url"); + + try { + options.getHostAddress(); + fail("Expected getHostAddress to throw"); + } catch (e: unknown) { + expect(e).toBeInstanceOf(Error); + const error = e as Error; + expect(error.message).toContain("Invalid endpoint URL:"); + expect(error.cause).toBeDefined(); + // The cause should be the original URL parsing error + expect((error.cause as Error).message).toBeDefined(); + expect((error.cause as Error).message.length).toBeGreaterThan(0); + } + }); }); describe("createChannelCredentials", () => {