-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
capture console issues as console errors #72468
Merged
huozhi
merged 2 commits into
canary
from
11-06-errors_handle_error_instance_from_console.error
Nov 11, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
...ages/next/src/client/components/react-dev-overlay/internal/helpers/capture-stack-trace.ts
This file was deleted.
Oops, something went wrong.
24 changes: 19 additions & 5 deletions
24
packages/next/src/client/components/react-dev-overlay/internal/helpers/console-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
// To distinguish from React error.digest, we use a different symbol here to determine if the error is from console.error or unhandled promise rejection. | ||
const digestSym = Symbol.for('next.console.error.digest') | ||
const consoleTypeSym = Symbol.for('next.console.error.type') | ||
|
||
// Represent non Error shape unhandled promise rejections or console.error errors. | ||
// Those errors will be captured and displayed in Error Overlay. | ||
type UnhandledError = Error & { digest: 'NEXT_UNHANDLED_ERROR' } | ||
type UnhandledError = Error & { | ||
[digestSym]: 'NEXT_UNHANDLED_ERROR' | ||
[consoleTypeSym]: 'string' | 'error' | ||
} | ||
|
||
export function createUnhandledError(message: string): UnhandledError { | ||
const error = new Error(message) as UnhandledError | ||
error.digest = 'NEXT_UNHANDLED_ERROR' | ||
export function createUnhandledError(message: string | Error): UnhandledError { | ||
const error = ( | ||
typeof message === 'string' ? new Error(message) : message | ||
) as UnhandledError | ||
error[digestSym] = 'NEXT_UNHANDLED_ERROR' | ||
error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error' | ||
return error | ||
} | ||
|
||
export const isUnhandledConsoleOrRejection = ( | ||
error: any | ||
): error is UnhandledError => { | ||
return error && error.digest === 'NEXT_UNHANDLED_ERROR' | ||
return error && error[digestSym] === 'NEXT_UNHANDLED_ERROR' | ||
} | ||
|
||
export const getUnhandledErrorType = (error: UnhandledError) => { | ||
return error[consoleTypeSym] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/development/app-dir/capture-console-error-owner-stack/app/browser/event/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
return ( | ||
<button | ||
onClick={() => { | ||
console.error('trigger an console <%s>', 'error') | ||
}} | ||
> | ||
click to error | ||
</button> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
test/development/app-dir/capture-console-error-owner-stack/app/browser/render-loop/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
for (let i = 0; i < 3; i++) { | ||
console.error('trigger an console.error in loop of render') | ||
} | ||
return <p>render</p> | ||
} |
6 changes: 6 additions & 0 deletions
6
test/development/app-dir/capture-console-error-owner-stack/app/browser/render/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
console.error('trigger an console.error in render') | ||
return <p>render</p> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/development/app-dir/capture-console-error-owner-stack/app/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
4 changes: 4 additions & 0 deletions
4
test/development/app-dir/capture-console-error-owner-stack/app/rsc/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function Page() { | ||
console.error(new Error('boom')) | ||
return <p>rsc</p> | ||
} |
6 changes: 6 additions & 0 deletions
6
test/development/app-dir/capture-console-error-owner-stack/app/ssr-error-instance/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
console.error(new Error('page error')) | ||
return <p>ssr</p> | ||
} |
8 changes: 8 additions & 0 deletions
8
test/development/app-dir/capture-console-error-owner-stack/app/ssr/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client' | ||
|
||
export default function Page() { | ||
console.error( | ||
'ssr console error:' + (typeof window === 'undefined' ? 'server' : 'client') | ||
) | ||
return <p>ssr</p> | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this doesn't currently handle when errors are in different positions e.g.
console.error('Failed to render', error)
? We need to track this shortcoming in Linear.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's a short solution for error capturing but having the correct trace. I marked the follow up work in NDX-459