Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception when fetch API rejects #1292

Closed
milesnash opened this issue Jul 14, 2022 · 0 comments · Fixed by #1294
Closed

Uncaught exception when fetch API rejects #1292

milesnash opened this issue Jul 14, 2022 · 0 comments · Fixed by #1294
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@milesnash
Copy link
Contributor

This issue is closely related to #1203 in terms of how it manifests for consumers of client libs that in turn use this lib for making requests. However, its source is in a close-but-separate area of the code.

Consider the following code:

import { DisksClient } from '@google-cloud/compute';

const client = new DisksClient();
const project = 'my-project';
const zone = 'us-east1';

try {
  const [disks] = await client.list({
    project,
    zone
  });
} catch (err) {
  console.error(err);
}

I expected to land in the catch block in the case of transient network errors such as ETIMEDOUT. However, my program still errors with the following:

{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "FetchError: request to https://compute.googleapis.com:443/compute/v1/projects/my-project/regions/us-east1/disks? failed, reason: connect ETIMEDOUT [REDACTED IP ADDR]:443",
    "reason": {
        "errorType": "FetchError",
        "errorMessage": "request to https://compute.googleapis.com:443/compute/v1/projects/my-project/regions/us-east1/disks? failed, reason: connect ETIMEDOUT [REDACTED IP ADDR]:443",
        "code": "ETIMEDOUT",
        "message": "request to https://compute.googleapis.com:443/compute/v1/projects/my-project/regions/us-east1/disks? failed, reason: connect ETIMEDOUT [REDACTED IP ADDR]:443",
        "type": "system",
        "errno": "ETIMEDOUT",
        "stack": [
            "FetchError: request to https://compute.googleapis.com:443/compute/v1/projects/my-project/regions/us-east1/disks? failed, reason: connect ETIMEDOUT [REDACTED IP ADDR]:443",
            "    at ClientRequest.<anonymous> (/var/task/node_modules/node-fetch/lib/index.js:1461:11)",
            "    at ClientRequest.emit (events.js:400:28)",
            "    at ClientRequest.emit (domain.js:475:12)",
            "    at TLSSocket.socketErrorListener (_http_client.js:475:9)",
            "    at TLSSocket.emit (events.js:400:28)",
            "    at TLSSocket.emit (domain.js:475:12)",
            "    at emitErrorNT (internal/streams/destroy.js:106:8)",
            "    at emitErrorCloseNT (internal/streams/destroy.js:74:3)",
            "    at processTicksAndRejections (internal/process/task_queues.js:82:21)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: FetchError: request to https://compute.googleapis.com:443/compute/v1/projects/my-project/regions/us-east1/disks? failed, reason: connect ETIMEDOUT [REDACTED IP ADDR]:443",
        "    at process.<anonymous> (/var/runtime/index.js:35:15)",
        "    at process.emit (events.js:400:28)",
        "    at process.emit (/var/task/src/functions/runner/exec/handler.js:623206:21)",
        "    at processPromiseRejections (internal/process/promises.js:245:33)",
        "    at processTicksAndRejections (internal/process/task_queues.js:96:32)"
    ]
}

The fetch error message in this example is generated in node-fetch here. The fetch() Web API would also reject in such circumstances as described here.

I believe that consumers of such client libs would want to handle these errors in the way I have shown above and as described in #1203.

@milesnash milesnash added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jul 14, 2022
This was referenced Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant