bdg uses semantic exit codes that communicate actionable information, not just success/failure. This enables agents to make programmatic decisions about retries, error recovery, and escalation.
bdg dom click "#missing-button"echo $? # 83 (RESOURCE_NOT_FOUND)bdg dom fill "input" "invalid" # Validation errorecho $? # 81 (INVALID_ARGUMENTS)bdg cdp Network.timeout --params '{}'echo $? # 102 (CDP_TIMEOUT)
All errors are returned in a structured format when using --json:
bdg dom click "#nonexistent" --json
{ "version": "0.6.0", "success": false, "error": "Element not found: #nonexistent", "exitCode": 83, "suggestion": "Verify selector exists on page. Use 'bdg dom query \"#nonexistent\"' to test selector."}
{ "success": false, "error": "Element not found: button.submit", "exitCode": 83, "suggestion": "Verify selector exists on page. Use 'bdg dom query \"button.submit\"' to test selector."}
bdg dom get 0 # After navigation invalidated cache
{ "success": false, "error": "Element at index 0 not accessible", "exitCode": 87, "suggestion": "Re-run query to refresh cache. DOM was modified or page navigated."}
Even without --json, errors provide structured context:
bdg dom click "#missing" 2>&1
Error: Element not found: #missingSuggestion: Verify selector exists on page. Use 'bdg dom query "#missing"' to test selector.Exit code: 83 (RESOURCE_NOT_FOUND)
Errors go to stderr - stdout remains clean for piping, even on failure
For commands with limited choices, bdg suggests corrections:
bdg cdp Network.getCokies # Typo in method name
Error: Method 'getCokies' not found in domain 'Network'Did you mean: Network.getCookies (edit distance: 2) Network.setCookies (edit distance: 3) Network.getAllCookies (edit distance: 4)Tip: Use 'bdg cdp Network --list' to see all available methodsExit code: 81 (INVALID_ARGUMENTS)
Levenshtein distance algorithm finds closest matches within edit distance of 3
{ "success": false, "error": "Element not found: #missing-button", "exitCode": 83, // RESOURCE_NOT_FOUND "suggestion": "Verify selector exists on page. Use 'bdg dom query \"#missing-button\"' to test selector."}
bdg dom query "button" # Caches nodeIds for indices 0, 1, 2# ... page navigates ...bdg dom click 0 # Index 0 nodeId is now stale
{ "success": false, "error": "Element at index 0 not accessible", "exitCode": 87, // STALE_CACHE (not RESOURCE_NOT_FOUND) "suggestion": "Re-run query to refresh cache. DOM was modified or page navigated."}
87 (STALE_CACHE) is recoverable - re-run query and retry. 83 (RESOURCE_NOT_FOUND) is not - selector is wrong.
bdg validates input before execution and provides specific error messages:
bdg dom scroll --down -50 # Negative scroll value
{ "success": false, "error": "Invalid scroll amount: -50. Must be positive.", "exitCode": 81, "suggestion": "Use --up 50 to scroll upward, or --down 50 to scroll downward."}
bdg network har /invalid/path
{ "success": false, "error": "Permission denied: /invalid/path", "exitCode": 82, "suggestion": "Check file permissions or use '-' to output to stdout."}