question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncatchable error is thrown when a HTTPS post request fails

See original GitHub issue

Bug Description

When making an HTTPS post request to a URL that doesn’t respond/exist, an AssertionError is thrown that cannot be caught by the consumer.

Reproducible By

Wrap a post request to an unreachable URL in a try…catch Observe how the script is terminated without the error being caught

Code example:

import {request} from 'undici'
try {
  await request("https://thisis.not/avalid/url", {method: "POST");
} catch {
  console.log("Error caught, this never happens");
}

Expected Behavior

The promise should be rejected so that the error can be caught and handled by the consumer

Logs

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(this.servername)

    at TLSSocket.<anonymous> (C:\path\node_modules\undici\lib\core\connect.js:61:11)
    at TLSSocket.emit (node:events:377:35)
    at emitErrorNT (node:internal/streams/destroy:193:8)
    at emitErrorCloseNT (node:internal/streams/destroy:158:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: null,
  expected: true,
  operator: '=='
}

Environment

Windows 10, Node v16.2.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
joaopedrocamposcommented, Jul 10, 2021

Hey guys! If still up to, I would love to try this fix 🙏

0reactions
ronagcommented, Jul 11, 2021

Merged fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do uncatchable exceptions exist in Javascript? - Stack Overflow
I guess the errors thrown in a separate execution context are catchable or not depending on whether you're willing to modify someone else's...
Read more >
Can't catch error using callback and on-error handler #2161
I'm writing an application that needs to be robust with respect to handling failed connections. Is this a bug, or am I doing...
Read more >
Handling errors - Node-RED
These are uncatchable errors. If it does notify the runtime properly, then it is a catchable error that can be used to trigger...
Read more >
412 Precondition Failed - HTTP - MDN Web Docs - Mozilla
If the hashes don't match, it means that the document has been edited in-between and a 412 Precondition Failed error is thrown.
Read more >
Fetch - Error Handling for Failed HTTP Responses and ...
A quick example of how to handle both network errors and HTTP errors (4xx or 5xx) for fetch requests in a single catch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found