MCPcopy Create free account
hub / github.com/Snowflyt/tinyeffect / handleErrorAsResult

Function handleErrorAsResult

test/README.example.spec.ts:811–824  ·  view source on GitHub ↗
(
      self: Effected<Effect.Error<ErrorName> | E, R>,
    )

Source from the content-addressed store, hash-verified

809 const err = <E>(error: E): Result<never, E> => ({ kind: "err", error });
810
811 const handleErrorAsResult = <R, E extends Effect, ErrorName extends string>(
812 self: Effected<Effect.Error<ErrorName> | E, R>,
813 ): Effected<E, Result<R, { error: ErrorName; message?: string }>> => {
814 const isErrorEffect = (name: string | symbol): name is `error:${ErrorName}` => {
815 if (typeof name === "symbol") return false;
816 return name.startsWith("error:");
817 };
818
819 return self
820 .andThen((value) => ok(value))
821 .handle(isErrorEffect, (({ effect, terminate }: any, message: any) => {
822 terminate(err({ error: effect.name.slice("error:".length), message }));
823 }) as never) as Effected<E, Result<R, { error: ErrorName; message?: string }>>;
824 };
825
826 type TypeError = Effect.Error<"type">;
827 const typeError: EffectFactory<TypeError> = error("type");

Callers 1

range2Function · 0.70

Calls 5

terminateFunction · 0.85
okFunction · 0.70
errFunction · 0.70
handleMethod · 0.65
andThenMethod · 0.65

Tested by

no test coverage detected