Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(browser): Centralize and improve error handling in browser commands #38

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eastlondoner
Copy link
Owner

This PR significantly improves error handling within the browser commands (open, act, observe, extract), making it more robust, consistent, and developer-friendly. The key improvements are:

  1. Centralized Error Types: A new file, src/commands/browser/stagehand/errors.ts, has been introduced to define all custom error classes used by the browser commands. This centralizes error management and improves code organization.

  2. Consistent Use of Async Generators: Error handling now consistently uses async generators (CommandGenerator) to yield error messages. This ensures that all errors are properly propagated and displayed to the user, even in asynchronous operations.

  3. Improved Error Message Formatting: Error messages are now more informative and include:

    • Error type (e.g., ActionError, NavigationError)
    • Specific error message
    • Optional debug information (when the --debug flag is used)
  4. Unified Error Handling Logic: A handleBrowserError function is used to standardize error handling across all browser commands, ensuring consistent error reporting.

  5. Duplicate Class Removal: Duplicate error class definitions have been removed. All browser commands now import and use the centralized error classes from errors.ts.

  6. Improved act command error handling: The act command specifically benefits from better error reporting, including details about the failed instruction, start/end URLs, and available DOM elements when an ActionError occurs.

These changes significantly improve the developer experience when working with cursor-tools browser commands, making it easier to diagnose and fix issues.

- Create dedicated errors.ts file for all error classes

- Update error handling to use async generators consistently

- Improve error message formatting and debug output

- Fix duplicate error class definitions

- Update imports to use centralized error types
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.

1 participant