Skip to content

arch: Standardized error classification across all bridges #143

@bbopen

Description

@bbopen

Overview

Multiple issues relate to inconsistent error handling and classification across bridges. This tracking issue proposes standardized error handling.

Related Issues

Proposed Architecture

Error Hierarchy

BridgeError (base)
├── BridgeProtocolError    - Invalid protocol, malformed responses
├── BridgeTimeoutError     - Request timeouts
├── BridgeDisposedError    - Operations after dispose
├── BridgeSerializationError - JSON.stringify/parse failures (NEW)
└── BridgeInstanceError    - Instance handle lifecycle errors (NEW)

Error Factory Functions

// src/runtime/errors.ts
export function createProtocolError(message: string, cause?: unknown): BridgeProtocolError {
  return new BridgeProtocolError(message, { cause });
}

export function createTimeoutError(operation: string, timeoutMs: number): BridgeTimeoutError {
  return new BridgeTimeoutError(`${operation} timed out after ${timeoutMs}ms`);
}

export function createSerializationError(direction: 'request' | 'response', cause: unknown): BridgeSerializationError {
  return new BridgeSerializationError(`Failed to serialize ${direction}`, { cause });
}

export function normalizeError(error: unknown): BridgeError {
  if (error instanceof BridgeError) return error;
  // Map Python ProtocolError, timeouts, etc.
}

Python-side Error Mapping

# Map Python exceptions to protocol error types
ERROR_TYPE_MAP = {
    'ProtocolError': 'protocol',
    'TimeoutError': 'timeout',
    'ValueError': 'validation',
}

Acceptance Criteria

  • All bridges use consistent Bridge* error types
  • JSON serialization failures throw BridgeSerializationError
  • Timeouts throw BridgeTimeoutError with duration info
  • Python ProtocolError maps to BridgeProtocolError
  • Instance handle errors are explicit
  • Protocol error payloads are validated
  • All 6 related issues can be closed

Scope

This fix touches:

  • src/runtime/errors.ts - new error types and factories
  • src/runtime/node.ts - error normalization
  • src/runtime/http.ts - error classification
  • src/runtime/pyodide.ts - error classification
  • runtime/python_bridge.py - error type mapping

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions