sveltejs/kit · error · ValidationError

new ValidationError(result.issues) — carries the Standard Sc

Error message

new ValidationError(result.issues) — carries the Standard Schema issues array

What it means

A remote function's argument validator implements Standard Schema; when `validate(arg)` reports `issues`, SvelteKit wraps them in a `ValidationError` and throws. For queries this becomes a 400-style failure returned to the client; for batched `requested()` iterations it surfaces as the 'Skipping ...' wrapper error.

Source

Thrown at packages/kit/src/runtime/app/server/remote/shared.js:35

				error(400, 'Bad Request');
			}
		};
	}

	// if 'unchecked', pass input through without validating
	if (validate_or_fn === 'unchecked') {
		return (arg) => arg;
	}

	// use https://standardschema.dev validator if provided
	if ('~standard' in validate_or_fn) {
		return async (arg) => {
			// access property and call method in one go to preserve potential this context
			const result = await validate_or_fn['~standard'].validate(arg);

			// if the `issues` field exists, the validation failed
			if (result.issues) {
				throw new ValidationError(result.issues);
			}

			return result.value;
		};
	}

	throw new Error(
		'Invalid validator passed to remote function. Expected "unchecked" or a Standard Schema (https://standardschema.dev)'
	);
}

/**
 * In case of a single remote function call, just returns the result.
 *
 * In case of a full page reload, returns the response for a remote function call,
 * either from the cache or by invoking the function.
 * Also saves an uneval'ed version of the result for later HTML inlining for hydration.
 *

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Run the same schema client-side (`schema.safeParse`) before calling the remote function to catch issues early.
  2. Loosen or correct the schema so legitimate inputs pass (e.g. coerce: `z.coerce.number()`).
  3. Fix the caller to send data in the shape the schema expects.
  4. Catch the ValidationError server-side and return a friendlier `error(400, ...)` message if needed.

Example fix

// before
const result = await updateProfile({ age: form.get('age') }); // '33' as string
// after
const parsed = z.object({ age: z.coerce.number() }).safeParse({ age: form.get('age') });
if (!parsed.success) showIssues(parsed.error.issues);
else await updateProfile(parsed.data);
Defensive patterns

Strategy: validation

Validate before calling

const parsed = schema.safeParse(arg);
if (!parsed.success) {
  // handle issues before calling the remote function
  throw parsed.error;
}

Type guard

function parseArg(schema, arg) {
  const r = schema.safeParse(arg);
  return r.success ? { ok: true, value: r.data } : { ok: false, issues: r.error.issues };
}

Try / catch

try {
  await myQuery(arg);
} catch (e) {
  if (e instanceof ValidationError) showIssues(e.issues);
  else throw e;
}

Prevention

When it happens

Trigger: Calling a remote `query`/`command`/`form` declared like `.query(fn, zodSchema)` (or Valibot/ArkType) with an argument that fails the schema — wrong type, missing field, failed refinement.

Common situations: Client sends unvalidated form/URL data; schema updated server-side so previously valid clients now fail; `parseInt` yielding `NaN` against a `z.number()`; empty string against a non-empty string schema.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/3b250ec6f341705f. Report an issue: GitHub.