Skip to content

unacy / ParseError

Class: ParseError

Defined in: packages/core/src/errors.ts:193

Error thrown when parsing a string into a format-tagged value fails.

Remarks

Thrown by Parser<T> implementations (and createParserWithSchema) when input validation fails. Carries the format name, original input, and a human-readable reason to help callers produce user-facing error messages.

Input strings longer than 50 characters are truncated with ... in the error message to keep logs readable.

Example

typescript
try {
  parseISO('not-a-date');
} catch (e) {
  if (e instanceof ParseError) {
    console.error(`Failed to parse ${e.format}: ${e.reason}`);
    console.error(`Input was: ${e.input}`);
  }
}

Pitfalls

NEVER catch ParseError silently and return a default value without logging — silent coercion hides data-integrity issues that may corrupt downstream state.

Extends

Constructors

Constructor

ts
new ParseError(
   format, 
   input, 
   reason): ParseError;

Defined in: packages/core/src/errors.ts:198

Parameters

ParameterType
formatstring
inputstring
reasonstring

Returns

ParseError

Overrides

UnacyError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
cause?publicunknownUnacyError.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
formatreadonlystring-packages/core/src/errors.ts:194
inputreadonlystring-packages/core/src/errors.ts:195
messagepublicstringUnacyError.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringUnacyError.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
reasonreadonlystring-packages/core/src/errors.ts:196
stack?publicstringUnacyError.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Released under the MIT License.