Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.07k stars 1.19k forks source link

[Event Hubs] Websocket errors in node are translated to [object Object] #29294

Open the-ress opened 6 months ago

the-ress commented 6 months ago

Describe the bug CbsClient throws Error: [object Object] instead of the actual error when using websocket in node.

To Reproduce Steps to reproduce the behavior:

  1. Install @azure/core-amqp and ws
  2. Save the javascript code below as repro.js
  3. Run node repro.js
repro.js contents ```javascript const { ConnectionContextBase } = require('@azure/core-amqp'); const { WebSocket } = require('ws'); const ctx = ConnectionContextBase.create({ config: { webSocket: WebSocket, endpoint: 'sb://example.invalid/', host: 'example.invalid', connectionString: 'Endpoint=sb://example.invalid/', sharedAccessKeyName: 'test', sharedAccessKey: 'test', }, connectionProperties: { userAgent: 'test', }, }); ctx.cbsSession.init() .catch(console.log); ```

Expected behavior CbsSession.init should throw something like Error: getaddrinfo ENOTFOUND example.invalid.

Actual behavior CbsSession.init throws an error with a meaningless message:

Error: [object Object]
    at translate (C:\Code\azure-websocket-error-repro\node_modules\@azure\core-amqp\dist\index.js:1076:42)
    at CbsClient.init (C:\Code\azure-websocket-error-repro\node_modules\@azure\core-amqp\dist\index.js:1688:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Additional context This is a minimal repro case. The real world scenario involves @azure/event-hubs and intermittent internet connection.

The websocket library throws an ErrorEvent object and core-amqp tries to convert it to a string, producing [object Object]. Earlier in that function, there's code handling websocket errors, but it doesn't cover node and doesn't propagate the specific error either.

Screenshots The actual error in my real world scenario. image

github-actions[bot] commented 6 months ago

@jeremymeng @maorleger @mpodwysocki

github-actions[bot] commented 6 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.