PortError.ts 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
Typeis aData.TaggedErrorthat 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)catchhandlers 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"
})
})
See
Type— the tagged error
Exports Grouped by Category
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
declare class Type
Module markers
moduleTag
Module tag.
Signature
declare const moduleTag: "@parischap/effect-lib/PortError/"