Skip to content

Commit

Permalink
Add additional error classes and error codes (#73862)
Browse files Browse the repository at this point in the history
Adds support for additional error classes in the error code SWC plugin.

Follow up for
#73332 (comment)
  • Loading branch information
gaojude authored Dec 13, 2024
1 parent 7a124bc commit c2e7c89
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 3 deletions.
39 changes: 37 additions & 2 deletions crates/next-error-code-swc-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,43 @@ struct NewError {
}

fn is_error_class_name(name: &str) -> bool {
// TODO: handle other error classes
name == "Error"
name == "AggregateError"
// built-in error classes
|| name == "Error"
|| name == "EvalError"
|| name == "RangeError"
|| name == "ReferenceError"
|| name == "SyntaxError"
|| name == "TypeError"
|| name == "URIError"
// custom error classes
|| name == "ApiError"
|| name == "BailoutToCSRError"
|| name == "BubbledError"
|| name == "CanaryOnlyError"
|| name == "Cancel"
|| name == "CompileError"
|| name == "CssSyntaxError"
|| name == "DecodeError"
|| name == "DynamicServerError"
|| name == "ExportError"
|| name == "FatalError"
|| name == "ImageError"
|| name == "InvariantError"
|| name == "ModuleBuildError"
|| name == "NestedMiddlewareError"
|| name == "NoFallbackError"
|| name == "NoSuchDeclarationError"
|| name == "PageSignatureError"
|| name == "PostCSSSyntaxError"
|| name == "ReadonlyHeadersError"
|| name == "ReadonlyRequestCookiesError"
|| name == "ReadonlyURLSearchParamsError"
|| name == "ResponseAborted"
|| name == "SerializableError"
|| name == "StaticGenBailoutError"
|| name == "TimeoutError"
|| name == "Warning"
}

// Get the string representation of the first argument of `new Error(...)`
Expand Down
93 changes: 92 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,5 +520,96 @@
"519": "[%s]: experimental.useLightningcss does not work with postcss plugins. Please remove 'useLightningcss: true' from your configuration.",
"520": "A default cacheLife profile must always be provided. This is a bug in Next.js.",
"521": "cache: 'no-store' used on fetch for %s with 'export const fetchCache = 'only-cache'",
"522": "Invariant: did not expect response writer to be written to for upgrade request"
"522": "Invariant: did not expect response writer to be written to for upgrade request",
"523": "generateDynamicFlightRenderResult should never be called in `next start` mode.",
"524": "Expected the \"use cache\" function %s to receive its encrypted bound arguments as the first argument.",
"525": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`headers\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"526": "Unknown expression type in abortOnSynchronousPlatformIOAccess.",
"527": "Page with \\`dynamic = \"force-dynamic\"\\` couldn't be exported. \\`output: \"export\"\\` requires all pages be renderable statically because there is not runtime server to dynamic render routes in this output format. Learn more: https://nextjs.org/docs/app/building-your-application/deploying/static-exports",
"528": "failed to decode param",
"529": "Failed to execute \"redirect\" on \"response\": Invalid status code",
"530": "Unknown modifier \"%s\"",
"531": "Expected describeListOfPropertyNames to be called with a non-empty list of strings.",
"532": "%s\n\n%s\n\n\\t%s%s\n",
"533": "Found pages with \\`fallback\\` enabled:\\n%s\\n%s\\n",
"534": "Route \"%s\" has a \\`generateMetadata\\` that depends on Request data (\\`cookies()\\`, etc...) or external data (\\`fetch(...)\\`, etc...) but the rest of the route was static or only used cached data (\\`\"use cache\"\\`). If you expected this route to be prerenderable update your \\`generateMetadata\\` to not use Request data and only use cached external data. Otherwise, add \\`await connection()\\` somewhere within this route to indicate explicitly it should not be prerendered.",
"535": "Export encountered errors on following paths:\\n\\t%s",
"536": "Unknown key \"%s\"",
"537": "Expected \\`fromDir\\` to be of type \\`string\\`, got \\`%s\\`",
"538": "`prerenderAndAbortInSequentialTasks` should not be called in edge runtime.",
"539": "Failed to decode path param(s).",
"540": "createInternalWaitUntil should never be called in minimal mode",
"541": "PhasedStream expected more phases to release but none were found.",
"542": "\"next/font\" requires SWC although Babel is being used due to a custom babel config being present.\\nRead more: https://nextjs.org/docs/messages/babel-font-loader-conflict",
"543": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used %s. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"544": "experimental.ppr",
"545": "unexpected input %s",
"546": "Native module not found: %s",
"547": "Missing workStore in AfterContext.runCallbacks",
"548": "The 'static' directory is reserved in Next.js and can not be used as the export out directory. https://nextjs.org/docs/messages/can-not-output-to-static",
"549": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`cookies\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"550": "Route %s couldn't be rendered statically because it used %s. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
"551": "experimental.turbo.unstablePersistentCaching",
"552": "%s\n\n%s\n\n\\t%s\n\n%s\n",
"553": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`%s\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"554": "%s requires options.context to be an Element",
"555": "Using \\`export * from '...'\\` in a page is disallowed. Please use \\`export { default } from '...'\\` instead.\\nRead more: https://nextjs.org/docs/messages/export-all-in-page",
"556": "`createRenderResumeDataCache` should not be called in edge runtime.",
"557": "Server Actions are not supported with static export.",
"558": "Route %s couldn't be rendered statically because it used \\`%s\\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
"559": "Expected the \"use cache\" function %s to receive %s bound arguments, got %s instead.",
"560": "[%s]: options.implementation.transformCss must be an 'lightningcss' transform function. Received %s",
"561": "[LightningCssMinifyPlugin]: implementation.transformCss must be an 'lightningcss' transform function. Received %s",
"562": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`connection\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"563": "Cannot call waitUntil() on an AwaiterOnce that was already awaited",
"564": "Expected workStore to exist when handling searchParams in a client Page.",
"565": "Expected \\`moduleId\\` to be of type \\`string\\`, got \\`%s\\`",
"566": "when/key requires at least one option key",
"567": "Expected an instance of Response to be returned",
"568": "Expected a route module to be one of app route or page",
"569": "`onTaskError` threw while handling an error thrown from an `after` task",
"570": "Missing Client Reference Manifest for %s.",
"571": "Missing encryption key for Server Actions",
"572": "Expected a finite number, got %s: %s",
"573": "Route \"%s\" has a \\`generateViewport\\` that could not finish rendering before %s was used. Follow the instructions in the error for this expression to resolve.",
"574": "PhasedStream expected at least one phase but none were found.",
"575": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`nextUrl.%s\\`.",
"576": "Route %s couldn't be rendered statically because it used %s. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
"577": "Route %s couldn't be rendered statically because it used a dynamic API. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
"578": "util/compare-position#getParentComparator required either options.parent or options.element",
"579": "No cached response",
"580": "Expected at least one segment",
"581": "Expected the bound arguments of \"use cache\" function %s to deserialize into an array, got %s instead.",
"582": "Route is configured with methods that cannot be statically generated.",
"583": "Route \"%s\" couldn't be rendered statically it accessed data without explicitly caching it. See more info here: https://nextjs.org/docs/messages/next-prerender-data",
"584": "PhasedStream expected no more phases to release but some were found.",
"585": "Page with \\`dynamic = \"force-dynamic\"\\` won't be rendered statically.",
"586": "Route \"%s\" couldn't be rendered statically because it used \\`%s\\`. See more info here: https://nextjs.org/docs/messages/next-prerender-data",
"587": "i18n support is not compatible with next export. See here for more info on deploying: https://nextjs.org/docs/messages/export-no-custom-routes",
"588": "The 'public' directory is reserved in Next.js and can not be used as the export out directory. https://nextjs.org/docs/messages/can-not-output-to-public",
"589": "postponed state and dev warmup immutable resume data cache should not be provided together",
"590": "Route \"%s\" has a \\`generateViewport\\` that depends on Request data (\\`cookies()\\`, etc...) or external data (\\`fetch(...)\\`, etc...) but the rest of the route was static or only used cached data (\\`\"use cache\"\\`). If you expected this route to be prerenderable update your \\`generateViewport\\` to not use Request data and only use cached external data. Otherwise, add \\`await connection()\\` somewhere within this route to indicate explicitly it should not be prerendered.",
"591": "`scheduleInSequentialTasks` should not be called in edge runtime.",
"592": "postponed state should not be provided when fallback params are provided",
"593": "Cannot \\`%s\\` on a ReactServerPrerenderResult that has already been consumed.",
"594": "query/focusable requires option.strategy to be one of [\"quick\", \"strict\", \"all\"]",
"595": "when/key requires option[\"%s\"] to be a function",
"596": "AMP Validation caused the export to fail. https://nextjs.org/docs/messages/amp-export-validation",
"597": "The NextURL configuration includes no locale \"%s\"",
"598": "Invariant: a Page with `dynamic = \"force-dynamic\"` did not trigger the dynamic pathway. This is a bug in Next.js",
"599": "Cannot call onClose on a WebNextResponse that is already closed",
"600": "Expected workStore to exist when handling params in a client segment such as a Layout or Template.",
"601": "Cannot call a class as a function",
"602": "`stringifyResumeDataCache` should not be called in edge runtime.",
"603": "Image Optimization using the default loader is not compatible with export.\n Possible solutions:\n - Use \\`next start\\` to run a server, which includes the Image Optimization API.\n - Configure \\`images.unoptimized = true\\` in \\`next.config.js\\` to disable the Image Optimization API.\n Read more: https://nextjs.org/docs/messages/export-image-api",
"604": "%s requires valid options.context",
"605": "Failed to load page with getStaticPaths for %s",
"606": "Missing manifest for Server Actions.",
"607": "experimental.dynamicIO",
"608": "Route \"%s\" has a \\`generateMetadata\\` that could not finish rendering before %s was used. Follow the instructions in the error for this expression to resolve.",
"609": "Route %s couldn't be rendered statically because it used IO that was not cached. See more info here: https://nextjs.org/docs/messages/dynamic-io",
"610": "Could not find a production build in the '%s' directory. Try building your app with 'next build' before starting the static export. https://nextjs.org/docs/messages/next-export-no-build-id",
"611": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`request.%s\\`.",
"612": "ServerPrerenderStreamResult cannot be consumed as a stream because it is not yet complete. status: %s",
"613": "Expected the input to be `string | string[]`"
}
Binary file modified packages/next/next_error_code_swc_plugin.wasm
Binary file not shown.

0 comments on commit c2e7c89

Please sign in to comment.