Output and exit codes
Output formats¶
-o (--output) chooses how results are printed:
| Format | What you get |
|---|---|
table |
Lists as tables of their most useful columns; single objects as key/value pairs. The default on a terminal |
json |
The operation's data, pretty printed, with numbers kept exact. The default when the output is piped or redirected |
yaml |
The same data as YAML |
raw |
Text results (HCL, logs, YAML exports) exactly as the server sent them; anything else as compact JSON |
clarive job list --limit 5 # table on a terminal clarive job list --limit 5 -o json | jq .total clarive rule get 42 --hcl -o raw > rule.hcl clarive topic get 4321 -o yaml
Choose the columns of a table with --columns:
clarive job list --columns name,status,bl,starttime clarive topic search --assigned-to-me --columns mid,title,status
The JSON is the operation's data with nothing added, so what you see is
what the REST API and the MCP tools return. Lists come as
{"items": [...], "total": N, "skip": 0, "limit": 50}; page through them
with --limit (at most 1000) and --skip.
Errors¶
Errors go to stderr, one line, in the form error: <code>: <message>:
$ clarive topic change-status 4321 Done error: forbidden: User jdoe may not move topic 4321 from 'New' to 'Done': From New to Done the workflow allows the roles Developer; in the projects of topic 4321 jdoe holds Tester
With -o json or --debug, the error's details follow as JSON (for
example every invalid parameter, or the reasons of a refused status
change), so a script can read them.
The codes are the API's: invalid_params, unauthorized, forbidden,
not_found, conflict, failed, throttled, unavailable (maintenance
mode), internal (a server error: the message gives a reference to look
up in the server log).
--debug also logs every HTTP request to stderr, with its parameters,
the response status and how long it took. Tokens and passwords never
appear in it.
Exit codes¶
Scripts can rely on these:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | The operation failed, was aborted (a destructive operation not confirmed), or local I/O failed |
| 2 | Usage error, or invalid_params from the server |
| 3 | Unauthorized: no token, or an invalid, expired or revoked one |
| 4 | Forbidden: a missing permission, or a read token used for a write |
| 5 | Not found |
| 6 | Conflict, e.g. the rule changed since you read it |
| 7 | Server error (internal, unsupported, or an answer the CLI did not expect) |
| 8 | Network error: the server could not be reached |
| 9 | job wait and job create --wait: the job ended without finishing OK |
For example, deploy and fail the pipeline step unless the job finished:
clarive job create QA 101,102 --wait --logs case $? in 0) echo deployed ;; 9) echo "the job failed"; exit 1 ;; *) echo "could not create the job"; exit 1 ;; esac
Terminal safety¶
Tables, key/value views, job log lines and error messages remove control
characters (terminal escape sequences, bells, carriage returns) from text
that comes from the server. Data stored in Clarive, such as a topic title
or a log line written by a script, cannot move your cursor, change your
terminal's title or hide text. -o json, -o yaml and -o raw print the
exact values, escaped by the format where it needs to.
Scripting tips¶
- Pipe the output and you get JSON; no flag needed. Add
-o jsonanyway in scripts so a run in a terminal behaves the same. - Use
jqto pick values:clarive job get 1234 | jq -r .status. - Give
--yesto destructive operations in scripts; without a terminal they are refused otherwise. - Pass long or nested parameters with
--params @file.yaml. - Check the exit code instead of parsing error messages.