Skip to main content
Every fallible operation in BlindCast returns Result<T, E> — a discriminated union — instead of throwing exceptions. This makes error handling explicit, type-safe, and impossible to accidentally ignore.
The CLI is the exception — it uses Unix exit codes instead of Result types. See CLI Error Codes.

The type

  • When ok is true, value holds the success payload.
  • When ok is false, error holds the typed error.
TypeScript narrows the type automatically based on the ok check.

Why not throw?

BlindCast uses Result in the player, uploader, and internal packages for these reasons:
  1. Errors are part of the API contract. A function’s return type documents what can go wrong — callers can’t miss it.
  2. No unexpected try/catch. You won’t accidentally swallow a crypto error in a generic catch block.
  3. TypeScript narrowing works naturally. After if (!result.ok), TypeScript knows result.error is typed and result.value is not accessible.
  4. Compatible with async/await. Result composes cleanly with Promise<Result<T, E>> — no need to mix try/catch with await.

Pattern 1: Early return

The simplest pattern — bail out immediately on failure:

Pattern 2: Switch on error code

When different errors need different handling:

Pattern 3: Unwrap helper

If you prefer to throw in contexts where any error is fatal (e.g., scripts, tests):

Where you’ll encounter Result types

TypeScript tips

Never access .value without checking .ok first

The error type varies per deliverable

Each library defines its own error type with a specific code union:
All error types share the shape { code: ErrorCode; message: string }. PlayerError additionally has an optional cause?: unknown field for wrapping underlying hls.js errors.