result

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package result defines chrome-cdp's uniform output envelope and the stable exit-code contract that both humans and the Claude skill depend on.

Index

Constants

View Source
const (
	ExitOK         = 0 // success
	ExitGeneric    = 1 // unclassified error
	ExitUsage      = 2 // bad flags/args, validated before touching Chrome
	ExitConnection = 3 // can't attach to / launch Chrome
	ExitTarget     = 4 // selector not found, nav/wait timeout, ambiguous/unknown target
	ExitCDP        = 5 // a CDP method returned an error
	ExitDaemon     = 6 // daemon not running / already running / stale lock
)

Exit codes are a stable, documented contract (see `chrome-cdp help exit-codes`). error.code strings are finer-grained and map onto these via ExitCodeFor.

View Source
const (
	CodeGeneric        = "generic"
	CodeUsage          = "usage"
	CodeConnection     = "connection_failed"
	CodeNotDebug       = "not_debug_enabled"
	CodeTargetTimeout  = "target_timeout"
	CodeTargetNotFound = "target_not_found"
	CodeAmbiguous      = "ambiguous_target"
	CodeNoTarget       = "no_current_target"
	CodeCDP            = "cdp_error"
	CodeDaemon         = "daemon_error"
)

Stable error.code strings emitted in the envelope's error object. Named so call sites don't scatter bare string literals.

Variables

This section is empty.

Functions

func ExitCodeFor

func ExitCodeFor(code string) int

ExitCodeFor returns the process exit code for an error.code string, defaulting to ExitGeneric for anything unrecognized.

Types

type Envelope

type Envelope struct {
	OK        bool        `json:"ok"`
	Command   string      `json:"command"`
	Target    *TargetInfo `json:"target,omitempty"`
	Result    any         `json:"result,omitempty"`
	Error     *Err        `json:"error,omitempty"`
	ElapsedMs int64       `json:"elapsed_ms"`
}

Envelope is the single JSON shape every command emits under --json.

func (Envelope) ExitCode

func (e Envelope) ExitCode() int

ExitCode returns the process exit code implied by this envelope.

func (Envelope) JSON

func (e Envelope) JSON() ([]byte, error)

JSON renders the envelope as a single compact JSON value.

type Err

type Err struct {
	Code    string
	Message string
	Details map[string]any
}

Err is a structured command failure with optional context Details.

func (Err) MarshalJSON

func (e Err) MarshalJSON() ([]byte, error)

MarshalJSON flattens Details into the error object alongside code and message (e.g. {"code","message","selector",...}). encoding/json sorts map keys, so output is deterministic; code and message always win over any Details key.

type ExitCodeDoc

type ExitCodeDoc struct {
	Code int
	Desc string
}

ExitCodeDoc documents one exit code for `chrome-cdp exit-codes`.

func ExitCodes

func ExitCodes() []ExitCodeDoc

ExitCodes is the single source for the documented exit-code contract; the exit-codes command renders it rather than repeating the strings.

type TargetInfo

type TargetInfo struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	URL   string `json:"url"`
}

TargetInfo identifies the tab a command acted on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL