import { Console, Effect, pipe, Schema as S } from "effect"
import { type ParseError, TreeFormatter } from "effect/ParseResult"
export const mapParseError = <A, E, R>(
effect: Effect.Effect<A, ParseError | E, R>
) =>
pipe(
effect,
Effect.catchTag("ParseError", (e) =>
Effect.gen(function*($) {
yield* Console.log(TreeFormatter.formatError(e))
return yield* Effect.fail("Other typed error" as const)
}))
)
const program = pipe(
"Something to decode",
S.decode(S.Literal("Something to decode")),
mapParseError,
Effect.mapError((e) => e)
)
import { Console, Effect, pipe, Schema as S } from "effect"
import { type ParseError, TreeFormatter } from "effect/ParseResult"
export const mapParseError = <A, E, R>(
effect: Effect.Effect<A, ParseError | E, R>
) =>
pipe(
effect,
Effect.catchTag("ParseError", (e) =>
Effect.gen(function*($) {
yield* Console.log(TreeFormatter.formatError(e))
return yield* Effect.fail("Other typed error" as const)
}))
)
const program = pipe(
"Something to decode",
S.decode(S.Literal("Something to decode")),
mapParseError,
Effect.mapError((e) => e)
)