Skip to content

Commit

Permalink
fix: log error cause (#56528)
Browse files Browse the repository at this point in the history
### What?

While debugging #56456, I noticed that we cut useful information, namely the `Error` instances' [`cause` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause).

### Why?

In #56456, it was hiding the following:

```sh
Error: getaddrinfo EAI_AGAIN undefined
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
    at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
  errno: -3001,
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: 'undefined'
}
```

which might be an indicator to the user what was going wrong with the `fetch` call.

### How?

If there is a `err.cause` property, log it together with `err.digest`


Note, this does not fix #56456 but might be useful to debug similar issues as well.
  • Loading branch information
balazsorban44 authored Oct 6, 2023
1 parent edb92a3 commit 67cd914
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/src/server/dev/log-app-dir-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isError from '../../lib/is-error'
import * as Log from '../../build/output/log'

export function logAppDirError(err: any) {
export function logAppDirError(err: unknown) {
if (isError(err) && err?.stack) {
const cleanedStack = err.stack.split('\n').map((line: string) =>
// Remove 'webpack-internal:' noise from the path
Expand All @@ -24,6 +24,8 @@ export function logAppDirError(err: any) {
if (typeof (err as any).digest !== 'undefined') {
console.error(`digest: ${JSON.stringify((err as any).digest)}`)
}

if (err.cause) console.error('Cause:', err.cause)
} else {
Log.error(err)
}
Expand Down

0 comments on commit 67cd914

Please sign in to comment.