From aacb7e14ea35c0f1172201591f5be1f37c3988c4 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 2 Jun 2023 13:14:07 -0400 Subject: [PATCH] rename onUnhandledError - > handleError --- .changeset/{on-unhandled-error.md => handle-error.md} | 4 ++-- docs/file-conventions/entry.server.md | 8 ++++---- integration/error-sanitization-test.ts | 4 ++-- packages/remix-cloudflare/index.ts | 2 +- packages/remix-deno/index.ts | 2 +- .../codemod/replace-remix-magic-imports/utils/export.ts | 2 +- packages/remix-eslint-config/rules/packageExports.js | 2 +- packages/remix-node/index.ts | 2 +- packages/remix-server-runtime/build.ts | 4 ++-- packages/remix-server-runtime/index.ts | 2 +- packages/remix-server-runtime/reexport.ts | 2 +- packages/remix-server-runtime/server.ts | 2 +- rollup.utils.js | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) rename .changeset/{on-unhandled-error.md => handle-error.md} (60%) diff --git a/.changeset/on-unhandled-error.md b/.changeset/handle-error.md similarity index 60% rename from .changeset/on-unhandled-error.md rename to .changeset/handle-error.md index 6806aad74f8..e4715b88854 100644 --- a/.changeset/on-unhandled-error.md +++ b/.changeset/handle-error.md @@ -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 { diff --git a/docs/file-conventions/entry.server.md b/docs/file-conventions/entry.server.md index 4019095551d..3a5a1abdb7e 100644 --- a/docs/file-conventions/entry.server.md +++ b/docs/file-conventions/entry.server.md @@ -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 ) { @@ -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. diff --git a/integration/error-sanitization-test.ts b/integration/error-sanitization-test.ts index ad918301485..34afa0f8a45 100644 --- a/integration/error-sanitization-test.ts +++ b/integration/error-sanitization-test.ts @@ -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( { @@ -463,7 +463,7 @@ test.describe("Error Sanitization", () => { }); } - export function onUnhandledError( + export function handleError( error: unknown, { request }: { request: Request }, ) { diff --git a/packages/remix-cloudflare/index.ts b/packages/remix-cloudflare/index.ts index 9d27898e2e4..98caa9bef8e 100644 --- a/packages/remix-cloudflare/index.ts +++ b/packages/remix-cloudflare/index.ts @@ -68,7 +68,7 @@ export type { MemoryUploadHandlerOptions, MetaDescriptor, MetaFunction, - OnUnhandledErrorFunction, + HandleErrorFunction, PageLinkDescriptor, RequestHandler, RouteComponent, diff --git a/packages/remix-deno/index.ts b/packages/remix-deno/index.ts index a4ec61f2d34..b09a8ddfedd 100644 --- a/packages/remix-deno/index.ts +++ b/packages/remix-deno/index.ts @@ -56,7 +56,7 @@ export type { MemoryUploadHandlerOptions, MetaDescriptor, MetaFunction, - OnUnhandledErrorFunction, + HandleErrorFunction, PageLinkDescriptor, RequestHandler, RouteComponent, diff --git a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts index 26b0e315398..c1e492933d1 100644 --- a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts +++ b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts @@ -68,7 +68,7 @@ const defaultRuntimeExports: ExportNames = { "MemoryUploadHandlerOptions", "MetaDescriptor", "MetaFunction", - "OnUnhandledErrorFunction", + "HandleErrorFunction", "PageLinkDescriptor", "RequestHandler", "RouteComponent", diff --git a/packages/remix-eslint-config/rules/packageExports.js b/packages/remix-eslint-config/rules/packageExports.js index 49892da0e93..92ce1b50cad 100644 --- a/packages/remix-eslint-config/rules/packageExports.js +++ b/packages/remix-eslint-config/rules/packageExports.js @@ -46,7 +46,7 @@ const defaultRuntimeExports = { "MemoryUploadHandlerOptions", "MetaDescriptor", "MetaFunction", - "OnUnhandledErrorFunction", + "HandleErrorFunction", "PageLinkDescriptor", "RequestHandler", "RouteComponent", diff --git a/packages/remix-node/index.ts b/packages/remix-node/index.ts index 20fa129bb1b..f16ec506627 100644 --- a/packages/remix-node/index.ts +++ b/packages/remix-node/index.ts @@ -79,7 +79,7 @@ export type { MemoryUploadHandlerOptions, MetaDescriptor, MetaFunction, - OnUnhandledErrorFunction, + HandleErrorFunction, PageLinkDescriptor, RequestHandler, RouteComponent, diff --git a/packages/remix-server-runtime/build.ts b/packages/remix-server-runtime/build.ts index 55d8deff5b3..7a5cbc5c606 100644 --- a/packages/remix-server-runtime/build.ts +++ b/packages/remix-server-runtime/build.ts @@ -32,7 +32,7 @@ export interface HandleDataRequestFunction { (response: Response, args: DataFunctionArgs): Promise | Response; } -export interface OnUnhandledErrorFunction { +export interface HandleErrorFunction { (error: unknown, args: DataFunctionArgs): void; } @@ -43,5 +43,5 @@ export interface OnUnhandledErrorFunction { export interface ServerEntryModule { default: HandleDocumentRequestFunction; handleDataRequest?: HandleDataRequestFunction; - onUnhandledError?: OnUnhandledErrorFunction; + handleError?: HandleErrorFunction; } diff --git a/packages/remix-server-runtime/index.ts b/packages/remix-server-runtime/index.ts index 19329ec5395..c88011e6359 100644 --- a/packages/remix-server-runtime/index.ts +++ b/packages/remix-server-runtime/index.ts @@ -60,7 +60,7 @@ export type { MemoryUploadHandlerOptions, MetaDescriptor, MetaFunction, - OnUnhandledErrorFunction, + HandleErrorFunction, PageLinkDescriptor, RequestHandler, RouteComponent, diff --git a/packages/remix-server-runtime/reexport.ts b/packages/remix-server-runtime/reexport.ts index 349e0577f19..365d91a9d8a 100644 --- a/packages/remix-server-runtime/reexport.ts +++ b/packages/remix-server-runtime/reexport.ts @@ -1,7 +1,7 @@ export type { HandleDataRequestFunction, HandleDocumentRequestFunction, - OnUnhandledErrorFunction, + HandleErrorFunction, ServerBuild, ServerEntryModule, } from "./build"; diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 1f600c988e1..533392f6b55 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -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); diff --git a/rollup.utils.js b/rollup.utils.js index 92ed91e989f..3da8600e857 100644 --- a/rollup.utils.js +++ b/rollup.utils.js @@ -358,7 +358,7 @@ function getMagicExports(packageName) { "LoaderFunction", "MetaDescriptor", "MetaFunction", - "OnUnhandledErrorFunction", + "HandleErrorFunction", "PageLinkDescriptor", "RequestHandler", "RouteComponent",