new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js · API reference · all subjects

error handling

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Error code transformation in Next.js

The swc-plugin for Next.js transforms Error instances by rewriting `new Error` or `Error` to include an additional property `__NEXT_ERROR_CODE`. The transformation uses `Object.defineProperty(new Error(...), "__NEXT_ERROR_CODE", { value: $code, enumerable: false, configurable: true })`. The `enumerable: false` setting ensures the error code won't show up in console logs while remaining accessible for telemetry. The `configurable: true` setting allows the error code to be overwritten, which is useful for transforming errors.

Error code mapping file location and structure

The error code mapping is stored in `packages/next/errors.json`. The structure is append-only with increment-based mapping of error codes to messages.

Automatic error code mapping update during build

Running `pnpm build` automatically updates `packages/next/errors.json` if new errors are introduced. The updated `errors.json` file must always be committed to avoid CI failures.

Two-pass error code build process

The build process uses a two-pass system: (1) First Pass - extracts new errors and temporarily stores them in `packages/next/.errors/*.json`. In CI, a build with new errors will fail. (2) Second Pass - updates `packages/next/errors.json` and reruns the build step to confirm no further new errors are introduced. This system ensures reliable ordering of inserted error codes during concurrent builds.

Rebuilding the error code plugin WASM

After modifying the error code plugin, rebuild the WASM file by running `pnpm build-error-code-plugin` and commit it to the repository. Pre-built artifacts simplify the build process so that `pnpm build` runs without requiring `cargo`.

Testing the error code plugin

Run `cargo test` inside the `crates/next-error-code-swc-plugin` directory to test the plugin.

Give your agent this brain