Skip to main content

Exit Codes

Every CLI command in The Shift Platform exits with a semantic exit code. These codes allow agents and scripts to determine exactly what happened without parsing output text.

Exit Code Table

CodeConstantMeaning
0EXIT_SUCCESSOperation completed successfully
1EXIT_ERRORGeneral or unexpected error
2EXIT_USER_ERRORInvalid input or missing arguments
3EXIT_NOT_INITIALIZEDNo store directory found (e.g., .yellowpages/ missing)
4EXIT_NOT_FOUNDRequested resource does not exist
5EXIT_CONNECTIONServer unreachable (gateway or API unavailable)

EXIT_OK is exported as an alias for EXIT_SUCCESS.

Importing Exit Codes

import {
EXIT_SUCCESS,
EXIT_ERROR,
EXIT_USER_ERROR,
EXIT_NOT_INITIALIZED,
EXIT_NOT_FOUND,
EXIT_CONNECTION,
} from "@shift/platform-core/exit-codes";

Using Exit Codes in Commands

Within a CLI command handler, use process.exit() with the appropriate code:

import { EXIT_NOT_FOUND, EXIT_USER_ERROR } from "@shift/platform-core/exit-codes";
import { error } from "@shift/platform-core/output";

// Validate input
if (!name) {
error("Service name is required");
process.exit(EXIT_USER_ERROR);
}

// Handle missing resource
const service = await store.findByName(name);
if (!service) {
error(`Service "${name}" not found`);
process.exit(EXIT_NOT_FOUND);
}

Agent Control Flow

Agents can use exit codes for programmatic decision-making without parsing stdout. Combined with the Quiet mode, this enables clean conditional logic:

Shell Script Example

# Check if a service exists before creating it
if shift-cli yp services get my-service --quiet 2>/dev/null; then
echo "Service already exists"
else
exit_code=$?
if [ $exit_code -eq 4 ]; then
echo "Service not found, creating..."
shift-cli yp services add --name my-service --language TypeScript
elif [ $exit_code -eq 3 ]; then
echo "Catalog not initialized, running init..."
shift-cli yp init
elif [ $exit_code -eq 5 ]; then
echo "Server unreachable, retrying later..."
else
echo "Unexpected error (exit code: $exit_code)"
fi
fi

Agent Decision Tree

An AI agent can map exit codes to specific recovery strategies:

Exit CodeAgent Action
0Proceed with the result
1Log error, escalate or retry
2Fix the command arguments and retry
3Run shift-cli yp init first, then retry
4Create the missing resource, or adjust the query
5Wait and retry, or check network configuration

Design Rationale

Numeric exit codes are the most universal interface a CLI can offer. They work across shells, programming languages, and operating systems. By assigning specific meanings to codes 0-5, The Shift Platform gives agents a reliable signal that does not depend on parsing text, language locale, or terminal capabilities.