File tree Expand file tree Collapse file tree
packages/durabletask-js-azuremanaged Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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" , ( ) => {
You can’t perform that action at this time.
0 commit comments