Exception: Browserctl::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/browserctl/errors.rb,
lib/browserctl/error/codes.rb,
lib/browserctl/error/exit_codes.rb,
lib/browserctl/error/suggested_actions.rb

Overview

Base error class for all browserctl daemon errors. Subclasses carry a machine-readable ‘code` that appears in wire responses. The canonical enum of stable codes lives in Codes; the sweep that retrofits every raise to use those codes lands in a later v0.12 PR.

Defined Under Namespace

Modules: Codes, ExitCodes, SuggestedActions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, code: self.class.default_code, context: {}) ⇒ Error

Returns a new instance of Error.



20
21
22
23
24
# File 'lib/browserctl/errors.rb', line 20

def initialize(msg = nil, code: self.class.default_code, context: {})
  @code    = code
  @context = context || {}
  super(msg)
end

Instance Attribute Details

#codeString (readonly)

machine-readable error code

Returns:

  • (String)

    the current value of code



15
16
17
# File 'lib/browserctl/errors.rb', line 15

def code
  @code
end

#contextHash (readonly)

free-form structured fields (selector, path, …)

Returns:

  • (Hash)

    the current value of context



15
16
17
# File 'lib/browserctl/errors.rb', line 15

def context
  @context
end

Class Method Details

.default_codeObject



16
# File 'lib/browserctl/errors.rb', line 16

def self.default_code = "error"

Instance Method Details

#to_payloadHash{Symbol => Object}

Returns the canonical structured payload emitted on the daemon wire and on CLI stderr. Shape is stable across releases — agents branch on ‘code` without parsing prose.

Returns:

  • (Hash{Symbol => Object})


30
31
32
33
34
35
36
37
# File 'lib/browserctl/errors.rb', line 30

def to_payload
  {
    code: code,
    message: message,
    context: context,
    suggested_action: SuggestedActions.for(code)
  }
end