sveltejs/kit · warning
Passing an `App.Error` body as the second argument is deprec
Error message
Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third
What it means
`error(status, body)` in $app/utils warns in dev when the second argument is an object rather than a string. The object's `message` property is used and the rest become `properties`, but this overload is deprecated in favor of `error(status, message, properties)`.
Source
Thrown at packages/kit/src/exports/index.js:88
* Throws an error with a HTTP status code and an optional message.
* When called during request handling, this will cause SvelteKit to
* return an error response; the error will be passed to `handleError` as an _expected_ error.
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
* @param {any} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
* @param {any} [message] A string, or (deprecated) a partial App.Error object
* @param {any} [properties] Additional properties of the App.Error type when passing a string message.
* @return {never}
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
* @throws {Error} If the provided status is invalid (not between 400 and 599).
*/
export function error(status, message, properties) {
if ((!BROWSER || DEV) && (isNaN(status) || status < 400 || status > 599)) {
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
}
if (message !== undefined && typeof message !== 'string') {
if (DEV) {
console.warn(
'Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third'
);
}
({ message, ...properties } = message);
}
throw new HttpError({ ...properties, status, message: message ?? `Error: ${status}` });
}
/**
* Checks whether this is an error thrown by {@link error}.
* @template {number} T
* @param {unknown} e
* @param {T} [status] The status to filter for.
* @return {e is (import('./public.js').HttpError & { status: T extends undefined ? never : T })}
*/
export function isHttpError(e, status) {View on GitHub (pinned to 03f1687fe6)
Solutions
- Split the call: pass the message string second and the remaining properties as a third argument
- Search the codebase for `error(` calls whose second argument is an object literal
- Update tests that assert on the deprecated overload
Example fix
// before
error(404, { message: 'Not found', code: 'MISSING' });
// after
error(404, 'Not found', { code: 'MISSING' }); Defensive patterns
Strategy: type-guard
Validate before calling
// helper to migrate calls safely
function kitError(status, message, properties) {
if (typeof message !== 'string') {
const { message: msg, ...props } = message;
return kitError(status, msg, props);
}
return { status, message, properties };
} Type guard
const isAppErrorBody = (m) => typeof m === 'object' && m !== null && typeof m.message === 'string';
Try / catch
// load/+server.js
import { error } from '@sveltejs/kit';
try {
if (!user) throw error(404, 'Not found', { code: 'MISSING' });
} catch (e) {
if (isHttpError(e)) return json({ code: e.body.code }, { status: e.status });
throw e;
} Prevention
- Wrap error() calls in project helpers enforcing the (status, message, properties) signature
- ESLint rule banning object literals as error()'s second argument
- Keep error helpers updated with the current @sveltejs/kit types
When it happens
Trigger: Calling `throw error(404, { message: 'Not found', code: 'X' })` in a load function or `+server.js` during dev (DEV only).
Common situations: Code written against older SvelteKit APIs before the three-argument signature existed; copied legacy error helpers.
Related errors
- `defineEnvVars` has moved — import it from `@sveltejs/kit/en
- HTTP error status codes must be between 400 and 599 — ${stat
- Error: ${status}
- Cannot `return error(...)` — use `error(...)` or `return fai
- The next HMR update will cause the page to reload
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/2d49fbb49a8a8373.
Report an issue: GitHub.