Skip to main content

Overview

StackProbe uses exit codes to communicate audit results, making it easy to integrate into CI/CD pipelines and automated workflows.

Exit Code Behavior

Exit Code 0 (Success)

StackProbe exits with code 0 when:
  • All checks pass
  • Checks pass with warnings only
  • All checks are skipped
Example scenarios:
# All checks pass
stackprobe audit
# Exit code: 0

# Some checks warn, but none fail
stackprobe audit
# Exit code: 0 (warnings don't fail the build)

Exit Code 1 (Failure)

StackProbe exits with code 1 when:
  • One or more checks fail
  • A check crashes unexpectedly
Implementation reference: runner.ts:84
// Exit with code 1 if any check failed — useful for CI
const hasFail = results.some((r) => r.status === "fail");
if (hasFail) process.exit(1);
Example scenarios:
# Dependency check fails
stackprobe audit
# Exit code: 1

# Specific check fails
stackprobe audit --only engine
# Exit code: 1 (if engine check fails)

Check Status Levels

Each check returns one of four status levels:
StatusImpact on Exit CodeDescription
passExit 0Check completed successfully with no issues
warnExit 0Check found potential issues but not critical
failExit 1Check found critical issues that must be fixed
skipExit 0Check was skipped (via ignore config)

CI/CD Integration

GitHub Actions

- name: Run StackProbe audit
  run: npx stackprobe audit
  # Workflow will fail if exit code is 1

GitLab CI

audit:
  script:
    - npx stackprobe audit
  # Job fails if exit code is non-zero

CircleCI

- run:
    name: StackProbe audit
    command: npx stackprobe audit

Using JSON Output in CI

Capture and parse JSON output for custom behavior:
# Capture JSON output
stackprobe audit --json > audit-results.json

# Check exit code
if [ $? -ne 0 ]; then
  echo "Audit failed"
  # Parse results for custom handling
  cat audit-results.json | jq '.results[] | select(.status == "fail")'
fi

Error Handling

If a check crashes unexpectedly, StackProbe handles it gracefully:
  1. The crashed check is reported as a fail status
  2. An error message is added to the results
  3. Other checks continue to run
  4. The audit exits with code 1
Implementation reference: runner.ts:58-71
try {
  const result = await checkFn();
  result.duration = Date.now() - checkStart;
  results.push(result);
} catch (err) {
  // If a check crashes, report it as a fail — don't crash the whole audit
  results.push({
    checkName: name,
    status: "fail",
    messages: [
      {
        level: "error",
        text: `Check crashed unexpectedly: ${(err as Error).message}`,
      },
    ],
    duration: Date.now() - checkStart,
  });
}

Best Practices

Warnings don’t fail builds — StackProbe only exits with code 1 for actual failures. This allows you to catch warnings without blocking deployments.
Fail-fast in CI:
stackprobe audit || exit 1
Continue on failure (not recommended):
stackprobe audit || true
Run specific checks in different CI stages:
# Fast checks first
- npx stackprobe audit --only deps,env

# Slower checks later
- npx stackprobe audit --only circular

Build docs developers (and LLMs) love