bitwarden / clients

Bitwarden client apps (web, browser extension, desktop, and cli).
https://bitwarden.com
Other
9.29k stars 1.25k forks source link

`bw update` does not handle DNS resolution failure gracefully #2738

Open ggiesen opened 3 years ago

ggiesen commented 3 years ago

Describe the Bug

When running bw update --response but DNS resolution is broken, unhandled exceptions are spewed on the console:

$ bw update --response
(node:3125580) UnhandledPromiseRejectionWarning: FetchError: request to https://api.github.com/repos/bitwarden/cli/releases/latest failed, reason: getaddrinfo ENOTFOUND api.github.com api.github.com:443
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/@bitwarden/cli/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:198:13)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at TLSSocket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:3125580) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3125580) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

instead of sending a json failure response

Steps To Reproduce

  1. Break DNS resolution by commenting out nameservers in /etc/resolv.conf
  2. Run bw update --response

Expected Result

A proper JSON response with some sort of failure message. Something like:

{"success":false,"data":{"noColor":true,"object":"message","title":"Unable to check for updates.","message":"Unable to resolve api.github.com"}}

Actual Result

$ bw update --response
(node:3125580) UnhandledPromiseRejectionWarning: FetchError: request to https://api.github.com/repos/bitwarden/cli/releases/latest failed, reason: getaddrinfo ENOTFOUND api.github.com api.github.com:443
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/@bitwarden/cli/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:198:13)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at TLSSocket.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:3125580) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3125580) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Environment

bitwarden-bot commented 2 years ago

Hi ggiesen, We're cleaning up our repositories in preparation for a major reorganization. Issues from last year will be marked as stale and closed after two weeks. If you still need help, comment to let us know and we'll look into it. Thanks!

ggiesen commented 2 years ago

ping