Skip to content

fix: replace bare Error throws with domain-specific error classes#24

Open
ntegrals wants to merge 1 commit intomasterfrom
fix/error-handling-consistency
Open

fix: replace bare Error throws with domain-specific error classes#24
ntegrals wants to merge 1 commit intomasterfrom
fix/error-handling-consistency

Conversation

@ntegrals
Copy link
Copy Markdown
Owner

@ntegrals ntegrals commented Apr 1, 2026

Summary

Replaces all 15 bare throw new Error() calls in production source code with domain-specific error classes, enabling callers to catch and handle specific failure types.

New error classes

SandboxError — file system access violations (path traversal, file not found, read-only, size limits)

class SandboxError extends OpenBrowserError {
  readonly filePath?: string;
}

BridgeError — MCP bridge failures (unknown resources, tool call errors)

class BridgeError extends OpenBrowserError {}

Changes by file

File Throws Error class used
sandbox/file-access.ts 8 SandboxError
viewport/viewport.ts 2 ViewportError
viewport/event-hub.ts 2 ViewportError
commands/extraction/extractor.ts 1 PageExtractionError
bridge/server.ts 1 BridgeError
bridge/client.ts 1 BridgeError
agent/instructions.ts 1 AgentError
agent/replay-recorder.ts 1 OpenBrowserError

Before / After

// Before — caller can't distinguish error types
try { await fileAccess.read('data.bin'); }
catch (e) { /* is this "not found" or "binary file" or "too large"? */ }

// After — caller can catch specific failures
try { await fileAccess.read('data.bin'); }
catch (e) {
  if (e instanceof SandboxError) {
    console.log(e.filePath); // "data.bin"
  }
}

What was NOT changed

  • Test files — test mocks legitimately throw new Error() to simulate failures
  • No runtime behavior changes — same messages, same throw points

Test plan

  • bun run build — all 3 packages compile clean
  • bun run test — all 364 tests pass
  • Verified zero bare throw new Error() remaining in production code

Add SandboxError and BridgeError classes, and replace all 15 bare
throw new Error() calls in production code with the appropriate
custom error type for better error handling downstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants