Skip to main content Link Search Menu Expand Document (external link)

PortError overview

Tagged error type used to capture exceptions thrown by native JavaScript functions when those functions are ported to the Effect world (e.g. JSON.parse, JSON.stringify).

Mental model

  • Type is a Data.TaggedError that wraps a thrown value (originalError) together with context describing where the throw came from (originalFunctionName, moduleName, libraryName).
  • Use this error in Effect.try (or equivalent) catch handlers to keep the original exception inspectable while moving error handling out of the throw/catch axis.

Quickstart

Example (Wrap a throwing native API)

import { Effect } from "effect"
import * as MPortError from "@parischap/effect-lib/MPortError"

const safeJSONParse = (s: string) =>
  Effect.try({
    try: () => JSON.parse(s),
    catch: (e) =>
      new MPortError.Type({
        originalError: e,
        originalFunctionName: "JSON.parse",
        moduleName: "my-module.ts",
        libraryName: "my-app"
      })
  })

Table of contents


Models

Type (class)

Tagged error wrapping an exception thrown by a native function call. Carries the original thrown value plus contextual identifiers to help locate the source.

Signature

export declare class Type

Module markers

moduleTag

Module tag.

Signature

export declare const moduleTag: "@parischap/effect-lib/PortError/"