A string literal type used as the tag discriminator
A unique string that identifies this error class
A FailureConstructor — a class whose instances carry the __tag property
The returned class extends Error and adds a __tag property set to the
provided tag. Tagged errors integrate with catchTags to enable
type-safe, pattern-matched error recovery.
Instances are constructed with an optional ErrorOptions (e.g. { cause })
and their message is set to the tag string.
import { failure, fn, pipe, catchTags, succeed, run } from "mini-effect";
const NotFound = failure("NotFound");
const Unauthorized = failure("Unauthorized");
const result = await run(
pipe(
fn(() => { throw new NotFound(); }),
catchTags({
NotFound: () => succeed("fallback"),
Unauthorized: () => succeed("login"),
}),
),
);
// => "fallback"
Creates a tagged error class identified by the given
tagstring.