Skip to content

Commit

Permalink
Fix default error logging to include stack traces (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle authored Oct 12, 2023
1 parent 4156d16 commit 4f735fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-trainers-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/remix-oxygen': patch
---

Update the Oxygen Remix adapter to make sure that stack traces are logged in production
8 changes: 6 additions & 2 deletions examples/express/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ function handleBotRequest(
},
onError(error: unknown) {
responseStatusCode = 500;
console.error(error);
console.error(
(error as Error)?.stack ? (error as Error).stack : error,
);
},
},
);
Expand Down Expand Up @@ -123,7 +125,9 @@ function handleBrowserRequest(
reject(error);
},
onError(error: unknown) {
console.error(error);
console.error(
(error as Error)?.stack ? (error as Error).stack : error,
);
responseStatusCode = 500;
},
},
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/remix-oxygen/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ declare global {
var __H2O_LOG_EVENT: undefined | ((event: H2OEvent) => void);
}

const originalErrorToString = Error.prototype.toString;
Error.prototype.toString = function () {
return this.stack || originalErrorToString.call(this);
};

export function createRequestHandler<Context = unknown>({
build,
mode,
Expand Down

0 comments on commit 4f735fd

Please sign in to comment.