shellkitshellkit
Guide
API reference
Examples
Changelog
Releases
llms.txt
GitHub
  • 简体中文
  • English
Guide
API reference
Examples
Changelog
Releases
llms.txt
GitHub
  • 简体中文
  • English
  • Getting started

    • Guide
    • Install and upgrade
    • Thirty seconds
  • Core concepts

    • Five hard rules
    • Bash 3.2 compatibility
    • Module map
    • POSIX subset
  • Common tasks

    • Cookbook
    • CLI framework
    • Machine-readable output
    • Security boundaries
    • Internationalisation
    • Testing and gates
    • Working with AI
  • Going further

    • Example projects
    • Man pages
    • Migration guide
    • Compatibility policy
    • Releasing
    • Contributing
    • Changelog
  • Troubleshooting

    • Troubleshooting
    • FAQ

Troubleshooting

Start with the exit code, then the symptom table. The exit code is part of the interface and it is more reliable than the logs -- logs can be changed by --no-color or a redirect, exit codes cannot.

Exit codes

CodeMacroMeaningTypical source
0SK_OKsuccess---
1SK_ERRgeneral errora command function calling fail "$SK_ERR"
2SK_USAGEusage errorbad arguments, unknown option, _sk_need_args
3SK_PRECONDprecondition unmetmissing command, not root, interactive without a default, lock unavailable
4SK_NETnetwork failurenet_download, net_wait_port timing out
5SK_VERIFYverification failuresha256 mismatch, docs disagree with code, vendor --check drift

Callers use this code to decide whether to retry: retry retries SK_NET only, and gives up immediately on SK_USAGE and SK_VERIFY -- a hundred retries of those produce the same answer.

Symptom → fix

SymptomMost likely causeWhat to do
$(...) captured a value with [INFO] in itsomething logged to stdoutlogs only via log_* (stderr); custom output with printf >&2
bad substitution${v^^} / ${v,,} usedswitch to tr a-z A-Z, see Bash 3.2
declare: -A: invalid optionassociative array useduse a case dispatch or two parallel arrays
command not found: mapfilemapfile usedswitch to while IFS= read -r
unbound variable pointing at an arrayempty array expanded under set -uwrite ${arr[@]+"${arr[@]}"}
the script exits from inside if run ...run failed and called die; exit ignores ifswitch to run --no-die and inspect the code
every deploy restarts the servicethe file is written without comparing contentcompare first, write only on change; fs_ensure_* is idempotent by design
config file mode turned into 644plain echo >> appenduse conf_set / fs_atomic_* (they go through cp -p and keep the mode)
two backups in the same second, only one survivesbackup names only had second resolutionsince 0.6.0 names carry pid and a sequence number; upgrade
lock_acquire never succeedsa previous run was SIGKILLed and left a lock directory without a pidsince 0.6.0 a pid-less lock gets a 5 second grace period before reclamation
make check goes red after a docs editgenerated artefacts were not refreshedrun ./shellkit docs, then bash po/messages.sh
check-docs reports unknown functionan example uses a function that does not exist or was renamedcheck the signature in the API reference
messages-check red every timethe pot carries absolute paths or line numbersregenerate with bash po/messages.sh (--no-location is baked in)

Three debugging disciplines

  1. Reproduce first, then change code. A fix without a stable reproduction only changes how the symptom looks.
  2. Judge on artefacts, not on "the command did not complain". Commands like gh issue close or gh issue create can print nothing at all when they succeed; read the state or the artefact back.
  3. Verify in reverse once. After fixing, confirm the test is red on the old code and green on the new one. A test that was never red proves nothing.

Debug switches

# turn on debug logging
SHELLKIT_DEBUG=1 ./bin/myapp start

# disable colour so logs paste cleanly
SHELLKIT_COLOR=never ./bin/myapp start

# non-interactive: every prompt takes its default; a prompt without one returns SK_PRECOND(3)
SHELLKIT_NONINTERACTIVE=1 ./bin/myapp start

# keep the temporary directory to inspect the scene afterwards
SHELLKIT_TMP_KEEP=1 ./bin/myapp start

Under SHELLKIT_NONINTERACTIVE=1, a prompt that has no default makes the library return 3 rather than block waiting for input. That converts "CI ran into an interactive point" into a clear failure instead of a hang.

Last updated: 11/22/26, 7:50 PM
Next
FAQ
给 AI 直读:llms.txt 一个文件读完整个站点的地图