Module: Browserctl::Commands::CliOutput
- Included in:
- Ask, Click, Cookie, Daemon, Dialog, Fill, Flow, Page, Resume, Screenshot, Session, State, Storage, Workflow
- Defined in:
- lib/browserctl/commands/cli_output.rb
Constant Summary collapse
- AUTH_REQUIRED_EXIT_CODE =
Browserctl::AuthRequiredError::AUTH_REQUIRED_EXIT_CODE
Instance Method Summary collapse
-
#exit_code_for(res) ⇒ Object
Maps a daemon error response onto a process exit code.
- #print_result(res) ⇒ Object
-
#structured_error_line(res, message) ⇒ Object
Builds the single-line structured payload emitted to stderr after the human-readable line.
Instance Method Details
#exit_code_for(res) ⇒ Object
Maps a daemon error response onto a process exit code. Defaults to 1; special-cased only for codes that callers programmatically branch on.
25 26 27 28 29 |
# File 'lib/browserctl/commands/cli_output.rb', line 25 def exit_code_for(res) return AUTH_REQUIRED_EXIT_CODE if (res[:code] || res["code"]) == "AUTH_REQUIRED" 1 end |
#print_result(res) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/browserctl/commands/cli_output.rb', line 12 def print_result(res) if res.is_a?(Hash) && (res[:error] || res["error"]) = res[:error] || res["error"] warn "Error: #{}" warn structured_error_line(res, ) puts res.to_json exit exit_code_for(res) end puts res.to_json end |
#structured_error_line(res, message) ⇒ Object
Builds the single-line structured payload emitted to stderr after the human-readable line. Agents parse this JSON deterministically. Shape: { code, message, context, suggested_action }.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/browserctl/commands/cli_output.rb', line 34 def structured_error_line(res, ) code = (res[:code] || res["code"] || Browserctl::Error::Codes::GENERIC).to_s context = res[:context] || res["context"] || {} action = res[:suggested_action] || res["suggested_action"] || Browserctl::Error::SuggestedActions.for(code) JSON.generate( code: code, message: , context: context, suggested_action: action ) end |