Getting started4 min read

Errors that guide you

Every failure returns a class, an exit code, and the decision it implies.

“Something went wrong” is not actionable. An agent has four possible reactions to a failure — retry, fix the request, re-establish something, or give up — and those are four different situations. So every failure carries a stable code and a stable exit status, and the table below is grouped by the reaction rather than sorted by number.

the shape of a failure
{
  "error": {
    "code": "invalid_region",
    "message": "region 100,200,800,600 does not fit inside 1920x1080"
  }
}

Branch on code. The message is for a human reading logs, and is allowed to change; the code is not.

The request is wrong

The request itself is wrong. Retrying will fail identically; something about the arguments or the geometry needs to change.

ExitCodeMeaning
2invalid_argumentsUnparsable or contradictory arguments.
4invalid_regionRegion is malformed, zero sized, or out of bounds.
5window_not_foundThe requested window does not exist.
7resize_failedThe requested resize could not be performed.
10incompatible_framesThe two frames cannot be compared.
12image_load_failedAn input image could not be read or decoded.
15invalid_durationA duration was zero, negative, or unparsable.
25invalid_presentation_policyThe presentation policy is malformed or self-contradictory.
26payload_budget_exceededThe required views cannot fit in the requested budget, even at their floors.

Something outside the request changed

Something outside the request changed. A retry may work, and a retry after re-establishing a session usually will.

ExitCodeMeaning
3display_unavailableThe X11 display could not be opened.
6capture_failedThe backend could not produce a frame.
9output_failedWriting the result failed.
13geometry_changedThe observed target changed shape or moved.
14target_lostThe observed target disappeared.

The session is in the wrong state

The session's state does not permit this. Create a new session, or wait for the one you have to become free.

ExitCodeMeaning
17session_not_foundThe session is not registered — closed, or the service restarted.
18session_busyThe session is running an observation; a second one, or a close, was refused.
19session_closedThe session has been closed.
20frame_not_availableThe requested frame ID is not retained, or was never captured.
21no_frame_availableThe session has not captured any frame yet.

The service refused or failed

The service could not do the work: absent, overloaded, or speaking a protocol the client does not understand.

ExitCodeMeaning
22service_unavailableNo `eensh serve` could be reached at the socket path.
23service_protocol_errorThe service could not decode a request, or a protocol version was refused.
24service_overloadedThe service refused work to preserve freshness.

A bug in the tool

A bug. The request was well-formed and the environment was fine, so this should not have happened.

ExitCodeMeaning
1internal_errorUnexpected internal failure.
8encode_failedPNG or JPEG encoding failed.
11comparison_failedThe comparison could not be performed.
16observation_failedThe observation could not be performed.

Not an error

Nothing failed. The operation completed and the condition simply did not occur.

ExitCodeMeaning
100—Timeout: the observation ran, the condition did not occur.

The two cases that are not errors at all

Two situations look like failures and are deliberately not ones. Both are worth knowing before you write error handling, because treating either as an error is the most common mistake in a first integration.

Errors cross the process boundary unchanged

A service error is mapped back to the status it would have had on the standalone path. A frame_not_available from eensh serve exits 20, exactly as the equivalent standalone command would. The table above stays the single source of truth whether or not a service is involved.