Skip to content

recover

DDataParser.recover(inner, fallback) wraps a parser and returns its output when it succeeds or a fallback value when it fails. Handy to ensure a safe value while still collecting errors (useful for partial DTOs, logs, migrations, etc.).

Interactive example

Parameters

  • inner: parser to protect.
  • recoveredValue: value returned when inner fails (and final output type).
  • checkers: applied to the final result (whether it comes from inner or the fallback).
  • errorMessage: generic message in case of failure before recovery.

Return value

A DataParserRecover. schema.parse(data) always returns DEither.success with either the result of inner or the fallback. Errors produced while running inner are still available in DataParserError for audit/logging.

Other examples

Extended mode

See also

  • date - Parser for dates
  • nil - Parser for null or undefined values

Released under the MIT license.