plainfp - v0.1.0
    Preparing search index...

    Function fromThrowable

    • Execute a synchronous function and capture thrown exceptions as err. Without onError, the raw thrown value is surfaced with type unknown; pass onError to map it into a domain error — the error type is entirely user-controlled.

      Type Parameters

      • T

      Parameters

      • fn: () => T

      Returns ResultType<T, unknown>

      const parsed = fromThrowable(
      () => JSON.parse(rawBody) as Order,
      (cause) => ({ code: "INVALID_JSON", cause }),
      )
    • Execute a synchronous function and capture thrown exceptions as err. Without onError, the raw thrown value is surfaced with type unknown; pass onError to map it into a domain error — the error type is entirely user-controlled.

      Type Parameters

      • T
      • E

      Parameters

      • fn: () => T
      • onError: (cause: unknown) => E

      Returns ResultType<T, E>

      const parsed = fromThrowable(
      () => JSON.parse(rawBody) as Order,
      (cause) => ({ code: "INVALID_JSON", cause }),
      )