Skip to content

Commit

Permalink
Improved error capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Dec 14, 2024
1 parent 13279df commit eae6bc3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/stack-shared/src/utils/errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ export function registerErrorSink(sink: (location: string, error: unknown) => vo
}
errorSinks.add(sink);
}
registerErrorSink((location, ...args) => {
console.error(`\x1b[41mCaptured error in ${location}:`, ...args, "\x1b[0m");
registerErrorSink((location, error, ...extraArgs) => {
console.error(
`\x1b[41mCaptured error in ${location}:`,
// HACK: Log a nicified version of the error to get around buggy Next.js pretty-printing
// https://www.reddit.com/r/nextjs/comments/1gkxdqe/comment/m19kxgn/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
errorToNiceString(error),
...extraArgs,
"\x1b[0m",
);
});
registerErrorSink((location, error, ...extraArgs) => {
globalVar.stackCapturedErrors = globalVar.stackCapturedErrors ?? [];
Expand All @@ -107,9 +114,7 @@ export function captureError(location: string, error: unknown): void {
for (const sink of errorSinks) {
sink(
location,
// HACK: Log a nicified version of the error instead of statusError to get around buggy Next.js pretty-printing
// https://www.reddit.com/r/nextjs/comments/1gkxdqe/comment/m19kxgn/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
errorToNiceString(error),
error,
...error && (typeof error === 'object' || typeof error === 'function') && "customCaptureExtraArgs" in error && Array.isArray(error.customCaptureExtraArgs) ? (error.customCaptureExtraArgs as any[]) : [],
);
}
Expand Down

0 comments on commit eae6bc3

Please sign in to comment.