Reference

Errors

The errors seroval throws, what causes them, and how to read them in production.

How errors are wrapped

Each function wraps any error it meets in one of three errors, by the step that failed. The original error is in the cause property.

ErrorThrown by
SerovalParserErrorEvery serialize function, when it cannot read the value.
SerovalSerializationErrorEvery function that produces JavaScript, when it cannot write the output.
SerovalDeserializationErrorfromJSON, fromCrossJSON and createCrossDeserializer, when the input is invalid.
JavaScript
import {
  SerovalParserError,
  SerovalUnsupportedTypeError,
  serialize,
} from 'seroval';

try {
  serialize({ callback: () => {} });
} catch (error) {
  error instanceof SerovalParserError; // true
  error.cause instanceof SerovalUnsupportedTypeError; // true
  error.cause.value; // the function
}

Specific errors

These usually arrive as the cause of a wrapper error.

ErrorCodeCause
SerovalUnsupportedTypeError1The value has a type seroval does not support, such as a function or a class instance with no plugin. The value is in value.
SerovalUnsupportedNodeError2The input has an unknown node type, or one that uses a disabled feature.
SerovalMissingPluginError3No plugin has the tag the input asks for.
SerovalMissingInstanceError4The input settles a promise or stream that does not exist.
SerovalMissingReferenceError5Deprecated. Not thrown by seroval.
SerovalMissingReferenceForIdError6The input refers to a createReference key that is not registered.
SerovalUnknownTypedArrayError7The input names an unknown typed array.
SerovalMalformedNodeError8A node in the input is malformed.
SerovalConflictedNodeIdError9The input declares the same value twice.
SerovalDepthLimitError10The value or input is nested deeper than depthLimit.
SerovalAbortedError11deserialize was called on a cross deserializer after abort.
SerovalLiveStreamError12A live stream was misused. reason is 'consumed', 'pending', 'reading' or 'closed'.

Messages in production

The production build of seroval replaces messages with codes, to stay small:

  • A wrapper error reads Seroval Error (step: N), where 1 is parsing, 2 is serialization and 3 is deserialization.
  • A specific error reads Seroval Error (specific: N), with the code from the table above.

The development build has full messages. Bundlers select it through the development export condition, which most of them set in development mode. The error classes are the same in both builds, so instanceof checks work everywhere.