Skip to content
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

rename onUnhandledError - > handleError #6524

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"@remix-run/server-runtime": minor
---

Add optional `onUnhandledError` export for custom server-side error processing. This is a new optional export from your `entry.server.tsx` that will be called with any encountered error on the Remix server (loader, action, or render error):
Add optional `handleError` export for custom server-side error processing. This is a new optional export from your `entry.server.tsx` that will be called with any encountered error on the Remix server (loader, action, or render error):

```ts
// entry.server.tsx
export function onUnhandledError(
export function handleError(
error: unknown,
{ request, params, context }: DataFunctionArgs
): void {
Expand Down
8 changes: 4 additions & 4 deletions docs/file-conventions/entry.server.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export function handleDataRequest(
}
```

## `onUnhandledError`
## `handleError`

By default, Remix will log encountered server-side errors to the console. If you'd like more control over the logging, or would like to also report these errors to an external service, then you can export an optional `onUnhandledError` function which will give you control (and will disable the built-in error logging).
By default, Remix will log encountered server-side errors to the console. If you'd like more control over the logging, or would like to also report these errors to an external service, then you can export an optional `handleError` function which will give you control (and will disable the built-in error logging).

```tsx
export function onUnhandledError(
export function handleError(
error: unknown,
{ request, params, context }: DataFunctionArgs
) {
Expand All @@ -39,7 +39,7 @@ export function onUnhandledError(

### Streaming Rendering Errors

When you are streaming your HTML responses via [`renderToPipeableStream`][rendertopipeablestream] or [`renderToReadableStream`][rendertoreadablestream], your own `onUnhandledError` implementation will only handle errors encountered uring the initial shell render. If you encounter a rendering error during subsequent streamed rendering you will need handle these errors manually since the Remix server has already sent the Response by that point.
When you are streaming your HTML responses via [`renderToPipeableStream`][rendertopipeablestream] or [`renderToReadableStream`][rendertoreadablestream], your own `handleError` implementation will only handle errors encountered uring the initial shell render. If you encounter a rendering error during subsequent streamed rendering you will need handle these errors manually since the Remix server has already sent the Response by that point.

- For `renderToPipeableStream`, you can handle these errors in the `onError` callback function. You will need to toggle a boolean when the in `onShellReady` so you know if the error was a shell rendering error (and can be ignored) or an async rendering error (and must be handled).
- For an exmaple, please see the default [`entry.server.tsx`][node-streaming-entry-server] for Node.
Expand Down
4 changes: 2 additions & 2 deletions integration/error-sanitization-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ test.describe("Error Sanitization", () => {
});
});

test.describe("serverMode=production (user-provided onUnhandledError)", () => {
test.describe("serverMode=production (user-provided handleError)", () => {
test.beforeAll(async () => {
fixture = await createFixture(
{
Expand Down Expand Up @@ -463,7 +463,7 @@ test.describe("Error Sanitization", () => {
});
}

export function onUnhandledError(
export function handleError(
error: unknown,
{ request }: { request: Request },
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type {
MemoryUploadHandlerOptions,
MetaDescriptor,
MetaFunction,
OnUnhandledErrorFunction,
HandleErrorFunction,
PageLinkDescriptor,
RequestHandler,
RouteComponent,
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type {
MemoryUploadHandlerOptions,
MetaDescriptor,
MetaFunction,
OnUnhandledErrorFunction,
HandleErrorFunction,
PageLinkDescriptor,
RequestHandler,
RouteComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const defaultRuntimeExports: ExportNames = {
"MemoryUploadHandlerOptions",
"MetaDescriptor",
"MetaFunction",
"OnUnhandledErrorFunction",
"HandleErrorFunction",
"PageLinkDescriptor",
"RequestHandler",
"RouteComponent",
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-eslint-config/rules/packageExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const defaultRuntimeExports = {
"MemoryUploadHandlerOptions",
"MetaDescriptor",
"MetaFunction",
"OnUnhandledErrorFunction",
"HandleErrorFunction",
"PageLinkDescriptor",
"RequestHandler",
"RouteComponent",
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type {
MemoryUploadHandlerOptions,
MetaDescriptor,
MetaFunction,
OnUnhandledErrorFunction,
HandleErrorFunction,
PageLinkDescriptor,
RequestHandler,
RouteComponent,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-server-runtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface HandleDataRequestFunction {
(response: Response, args: DataFunctionArgs): Promise<Response> | Response;
}

export interface OnUnhandledErrorFunction {
export interface HandleErrorFunction {
(error: unknown, args: DataFunctionArgs): void;
}

Expand All @@ -43,5 +43,5 @@ export interface OnUnhandledErrorFunction {
export interface ServerEntryModule {
default: HandleDocumentRequestFunction;
handleDataRequest?: HandleDataRequestFunction;
onUnhandledError?: OnUnhandledErrorFunction;
handleError?: HandleErrorFunction;
}
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type {
MemoryUploadHandlerOptions,
MetaDescriptor,
MetaFunction,
OnUnhandledErrorFunction,
HandleErrorFunction,
PageLinkDescriptor,
RequestHandler,
RouteComponent,
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/reexport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type {
HandleDataRequestFunction,
HandleDocumentRequestFunction,
OnUnhandledErrorFunction,
HandleErrorFunction,
ServerBuild,
ServerEntryModule,
} from "./build";
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
let staticHandler = createStaticHandler(dataRoutes);

let errorHandler =
build.entry.module.onUnhandledError ||
build.entry.module.handleError ||
((error, { request }) => {
if (serverMode !== ServerMode.Test && !request.signal.aborted) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion rollup.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function getMagicExports(packageName) {
"LoaderFunction",
"MetaDescriptor",
"MetaFunction",
"OnUnhandledErrorFunction",
"HandleErrorFunction",
"PageLinkDescriptor",
"RequestHandler",
"RouteComponent",
Expand Down