All StrataDB CLI commands return an error message and a non-zero exit code on failure. Errors have structured categories so you can handle them in scripts.

CLI Error Output

Errors are displayed with the error category:

$ strata --cache
strata:default/default> kv get missing
(nil)
strata:default/default> use nonexistent
(error) BranchNotFound: branch "nonexistent" does not exist

In shell mode, check exit codes:

if strata --cache branch exists my-branch; then
    echo "Branch exists"
else
    echo "Branch does not exist"
fi

Error Categories

Not Found Errors

Returned when an entity doesn’t exist.

ErrorWhen
BranchNotFoundBranch doesn’t exist
CollectionNotFoundVector collection doesn’t exist

Note: kv get returns (nil) for missing keys, not an error. Similarly for state get and json get.

Validation Errors

Returned when input is malformed.

ErrorWhen
InvalidKeyKey format is invalid
InvalidPathJSON path is malformed
InvalidInputGeneral input validation failure

Concurrency Errors

Returned when concurrent operations conflict.

ErrorWhen
VersionConflictCAS version doesn’t match
TransactionConflictCommit-time validation failure

State Errors

Returned when an operation violates state constraints.

ErrorWhen
BranchExistsCreating a branch that already exists
CollectionExistsCreating a collection that already exists

Constraint Errors

Returned when limits or constraints are violated.

ErrorWhen
DimensionMismatchVector dimension doesn’t match collection
ConstraintViolationGeneral constraint violation (e.g., deleting default branch)

Transaction Errors

Returned during transaction lifecycle issues.

ErrorWhen
TransactionNotActiveCommit/rollback without an active transaction
TransactionAlreadyActiveBegin while a transaction is already open
TransactionConflictCommit-time validation failure

Common Patterns

Handle Specific Errors in Scripts

#!/bin/bash
set -euo pipefail

# Create branch only if it doesn't exist
if ! strata --cache branch create my-branch 2>/dev/null; then
    echo "Branch already exists (or other error)"
fi

Transaction Retry

#!/bin/bash
set -euo pipefail

for attempt in 1 2 3 4 5; do
    strata --db ./data <<'EOF' && break
begin
kv get counter
kv put counter 1
commit
EOF
    echo "Conflict on attempt $attempt, retrying..."
done

Idempotent Operations

Use state init for idempotent initialization and check for BranchExists:

# Create branch only if it doesn't exist
strata --cache branch create session-001 2>/dev/null || true

# Initialize state idempotently
strata --cache state init status idle

Next