Circle V2 API Docs
    Preparing search index...

    Module @repo/safe

    @repo/safe

    @repo/safe is a Go-inspired result type used throughout the stack for explicit error handling. It exports discriminated union types Safe<T>, SafeSuccess<T>, and SafeError, along with the safe() wrapper function (handles sync and async), safeSuccess(), safeError(), and unwrap().

    %%{init:{"theme":"dark"}}%% graph TD safe["@repo/safe"] --> errors["@repo/errors"] safe -.-> typescript_config["@repo/typescript-config"] safe -.-> vitest_config["@repo/vitest-config"]
    %%{init:{"theme":"default"}}%% graph TD safe["@repo/safe"] --> errors["@repo/errors"] safe -.-> typescript_config["@repo/typescript-config"] safe -.-> vitest_config["@repo/vitest-config"]
    graph TD
      safe["@repo/safe"] --> errors["@repo/errors"]
      safe -.-> typescript_config["@repo/typescript-config"]
      safe -.-> vitest_config["@repo/vitest-config"]
    import { safe, unwrap, type Safe } from "@repo/safe";

    // Wrap any function call
    const result = await safe(async () => {
    return await fetchData();
    });

    if (result.error) {
    console.error(result.error.message);
    return;
    }

    console.log(result.data);

    // Or unwrap to throw on error
    const data = unwrap(result);
    Script Description
    test Runs Vitest with coverage.
    test:watch Runs Vitest in watch mode.
    check-types Runs tsc --noEmit to typecheck the package.

    Type Aliases

    Safe
    SafeError
    SafeResult
    SafeReturnType
    SafeSuccess
    SafeValue

    Functions

    safe
    safeError
    safeSuccess
    unwrap