Hyperlinkv0.8.0-beta.28

Exit

Exit.mapErrorconsteffect/Exit.ts:871
<E, E2>(f: (a: NoInfer<E>) => E2): <A>(self: Exit<A, E>) => Exit<A, E2>
<A, E, E2>(self: Exit<A, E>, f: (a: NoInfer<E>) => E2): Exit<A, E2>

Transforms the typed error of a failed Exit using the given function.

When to use

Use to remap typed errors while preserving the Exit structure

Details

Successes pass through unchanged.

Allocates a new Exit if the error is transformed.

Gotchas

Only transforms typed errors (Fail reasons). If the Cause contains only defects or interruptions, the failure passes through unchanged.

Example (Mapping over an error)

import { Data, Exit } from "effect"

class ExitError extends Data.TaggedError("ExitError")<{ readonly input: string }> {}

const exit = Exit.fail("bad input")
const mapped = Exit.mapError(exit, (e) => new ExitError({ input: e }))
console.log(Exit.isFailure(mapped)) // true
combinatorsmapmapBoth
Source effect/Exit.ts:8714 lines
export const mapError: {
  <E, E2>(f: (a: NoInfer<E>) => E2): <A>(self: Exit<A, E>) => Exit<A, E2>
  <A, E, E2>(self: Exit<A, E>, f: (a: NoInfer<E>) => E2): Exit<A, E2>
} = effect.exitMapError