Skip to main content
Community Scripts logo
Function reference

Error handling

What catch_errors installs, how a failure is reported and explained, the recovery menu after a failed install, and where the logs are.

Error handling lives in core/error_handler.func. A script enables it with one call and from then on must not install its own ERR or EXIT traps.

catch_errors

catch_errors

No arguments. It runs set -Ee -o pipefail and installs five traps:

TrapHandlerResult
ERRerror_handlerreport, explain, exit with the failing command's code
EXITon_exitfinal bookkeeping on every exit, successful or not
INTon_interruptInterrupted by user (SIGINT), exit 130
TERMon_terminateTerminated by signal (SIGTERM), exit 143
HUPon_hangupoutput moves to the log, the run continues

set -u is added only when STRICT_UNSET=1.

Who calls it:

  • ui/build-ui.func right after loading core/core.func and this file, so the engine is covered while it loads.

  • Every ct script, after variables and color (ct/vaultwarden.sh):

    header_info "$APP"
    variables
    color
    catch_errors

    On a Proxmox VE host this second call matters: pve/backend.func sets its own EXIT, ERR, INT and TERM traps when it loads, and the script's catch_errors puts the handlers described here back in place.

  • lxc/install.func during the container bootstrap, and every install script again after verb_ip6 (install/vaultwarden-install.sh):

    source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
    color
    verb_ip6
    catch_errors
    setting_up_container
    network_check
    update_os
  • Add-on scripts, after sourcing the files themselves.

On Incus hosts incus/core.func redefines catch_errors and error_handler as its own incus_catch_errors and incus_error_handler, and incus/build.func installs its own signal traps. The rest of this page describes the handlers in core/error_handler.func, which are the ones used on Proxmox VE hosts and inside containers on both platforms.

What "failure" means

With set -e and the ERR trap, any command that returns non-zero ends the run, unless it is part of a condition (if, while, &&, ||) or you add || true. Commands run through $STD behave the same way: silent returns the command's status and the trap fires on that line.

What error_handler does

In order:

  1. Works out the exit code, the command and the line. If the failing command ran through silent, the real command, its line and its captured output replace what the trap saw (which would only be the silent wrapper or a helper's return).
  2. Treats the failure as exit 130 when the captured output shows that the command received a Ctrl-C (received signal 2 or KeyboardInterrupt).
  3. Inside a $( ) or ( ) subshell it only exits with the code; the calling shell fails on the same error and reports it once.
  4. Stops the spinner and restores the cursor.
  5. Reports the failure once (see Who reports).
  6. Prints the error line.
  7. Prints what the failing command printed.
  8. Prints hints for known causes.
  9. On the host: prints Full log: <path> and offers to remove a half-built container.
  10. Exits with the original exit code.

The error line

✖️  in line 24: exit code 100 (APT: Package manager error (broken packages / dependency problems)): while executing command apt install -y build-essential
PartMeaning
in line NLine of the script that was running. The host passes an install script to bash -c behind one extra line, so there N is one higher than the line in install/<app>-install.sh
exit code CThe command's exit status
(explanation)Text for that status, see below
while executing command …The command, with the $STD prefix removed

The explanation normally comes from explain_exit_code, the table on the Exit codes page. The handler adjusts it to the command that actually ran, because many tools reuse the same numbers:

SituationExplanation shown
Exit 1 from (( … ))Arithmetic expression evaluated to 0
Exit 1 from [[ … ]], [ … ] or testTest condition was false
VAR=$(…) failedCommand substitution exited with status N
Exit 1 from grep, egrep, fgrep, zgrep, rggrep found no match (with the tool's name)
Exit 5 from systemctlSystemd: unit not found
The command is return or exitExit status N
The table entry belongs to a tool family (curl, APT, DPKG, Node.js, Python, PostgreSQL, MySQL/MariaDB, MongoDB, Systemd, git) and a different program ran<program> exited with status N
Exit 1, 2 or 3 from a known program<program> exited with status N

So cargo build failing with 101 is reported as cargo exited with status 101, not as the APT configuration error that 101 means for apt.

Output of the failing command

One of three blocks follows the error line, written to stderr:

HeadingShown whenContent
--- Output of the failing command ---the command ran through $STDup to 25 lines of that command's own output
--- Output of the failing step ---otherwise, and api/errorlog.func is loadedthe log from the last [INFO]/[OK] line on, with progress noise removed, last 25 lines
--- Last 20 lines of log ---otherwisethe tail of the active log

Hints

ConditionHint
Exit 127 and a command word that is not installed<name> is not installed or not on PATH, plus where it normally comes from (setup_nodejs, setup_rust, setup_go, /usr/local/bin). Nothing is installed for you
Exit 243, or the log mentions a JavaScript heap limit, or exit 134/137 from an npm, pnpm, yarn, node, vite or turbo commandPossible Node.js heap OOM. Try: export NODE_OPTIONS="--max-old-space-size=<MB>". The value is 75 % of the memory found, between 1024 and 12288
Log shows unmet or broken package dependenciesAPT dependency conflict, or a PostgreSQL version conflict when a postgresql-<N> package is named
Log shows ERR_PNPM_OUTDATED_LOCKFILE, ERR_PNPM_LOCKFILE_CONFIG_MISMATCH or ELOCKVERIFYThe release's lockfile does not match its package.json
Log shows NO_PUBKEY, KEYEXPIRED, is not signed, sqvAPT repository signature error
Log shows Could not resolve, Failed to fetch, Network is unreachable and similarNetwork or DNS failure
Log shows Could not get lock, E: Unable to lockAPT or dpkg lock conflict
Log shows No space left on device, ENOSPC, disk quota exceededDisk space exhausted

The log-based hints look at the last 60 lines of the log and only the first matching row is shown.

Who reports: host and container

One run sends one terminal telemetry event, and the host sends it.

SideWhat happens on failure
ContainerNothing is sent. The handler writes /root/.install-<SESSION_ID>.failed (the exit code) and /root/.install-<SESSION_ID>.log.errinfo (the capture)
HostWrites <log>.errinfo and calls post_update_to_api "failed" <code>

The handler decides which side it is on with TELEMETRY_CONTEXT (lxc/install.func exports container), and otherwise by looking for pveversion, pct or incus.

The container is not silent on telemetry altogether: lxc/install.func sends progress pings (post_progress_to_api) while the install runs. Only the final status comes from the host. See Telemetry.

The .errinfo capture

Written by silent and by the error handler; the format is defined at the top of api/errorlog.func:

EXIT_CODE=100
LINE=24
COMMAND=apt install -y build-essential
FUNCTION=setup_deb_based
STEP=Installing Dependencies
MESSAGE=
PHASE=container
--- OUTPUT ---
E: Unable to locate package build-essential

STEP is the text of the msg_info that was open, or after <text> of the last msg_ok. MESSAGE is the first msg_error of that step. PHASE is host or container.

build_error_string turns this into the trace telemetry receives:

exit_code=100 | APT: Package manager error (broken packages / dependency problems) | step: Installing Dependencies | in setup_deb_based | at line 24: apt install -y build-essential
---
E: Unable to locate package build-essential

Before it is sent, the output is reduced to the failing step, package-manager and download progress lines are removed, IPv4 addresses are shortened to <first octet>.x.x.x, and the result is limited to 60 lines and 10240 bytes.

Failures on the host

When a host-side step fails after the container exists, the handler asks:

Remove broken container 105? (Y/n) [auto-remove in 60s]:
AnswerResult
Enter, ycontainer stopped and destroyed
nContainer 105 kept for debugging
no answer for 60 secondscontainer stopped and destroyed
the terminal cannot be readcontainer kept; pct destroy <id> is printed for manual removal

The question is only asked for a container this run created (_CS_CREATED_CTID). An add-on that sets CTID to an existing container never gets it.

The recovery menu after a failed install

A failure of the install script inside the container is handled by build_container in pve/backend.func, not by the ERR trap. After lxc-attach returns, the host reads /root/.install-<SESSION_ID>.failed from the container. If it exists (or lxc-attach itself returned non-zero), the host:

  1. prints Installation failed in container <CTID> (exit code: N);
  2. builds a combined log, /tmp/<app>-<CTID>-<SESSION_ID>.log, from the host build log ("PHASE 1") and the install log pulled out of the container ("PHASE 2"), and pulls the .errinfo capture;
  3. reports the failure to telemetry;
  4. prints Installation log: <path> and Error: <explanation>;
  5. shows the menu.
What would you like to do?

  1) Remove container and exit
  2) Keep container for debugging
  3) Retry with verbose mode (full rebuild)
  4) Repair APT/DPKG state and re-run install (in-place)

Select option [1-4] (default: 1, auto-remove in 60s):

Options 1 to 3 are always there. The others appear when the failure looks like a case they can fix, and are numbered from 4 in this order:

OptionOffered whenWhat it does
Remove container and exitalwayspct stop, pct destroy, exit with the install's code
Keep container for debuggingalwaysleaves the container running and exits with the install's code
Retry with verbose mode (full rebuild)alwaysdestroys the container, picks a valid container ID again, sets VERBOSE=yes and runs build_container again with the same settings
Repair APT/DPKG state and re-run install (in-place)exit 100, 101 or 102 from an apt/dpkg command; exit 255 or 1 with apt/dpkg errors in the outputruns dpkg --configure -a, apt-get -f install -y, apt-get clean, apt-get update in the container, then runs the install script again in the same container, verbose
Repair APK state and re-run install (in-place)the same, on Alpineapk fix, apk cache clean, apk update, then the install script again
Retry with more resources (RAM: …, CPU: …)exit 134, 137 or 243; exit 1 with out-of-memory messagesdestroys the container and rebuilds with RAM and cores doubled. Offered twice at most
Retry with more disk space (Disk: …)exit 228 or 23; ENOSPC or No space left on device in the outputdestroys the container and rebuilds with the disk size doubled. Offered twice at most
Retry with DNS override in LXC (8.8.8.8 / 1.1.1.1)exit 6, 7, 22, 28, 35, 52, 56, 57, 75 or 78; exit 100 or 128 with network errors in the output; exit 1 with resolver or connection errorsdestroys the container and rebuilds; after the base setup /etc/resolv.conf in the container is set to 8.8.8.8 and 1.1.1.1

How the prompt resolves:

InputResult
Enteroption 1
nothing for 60 secondscontainer removed
a number that is not offeredInvalid option. Container <CTID> kept.
the terminal cannot be readcontainer kept
the console was closed during the installoption 2 is taken automatically

If the in-place repair does not help, the container is kept and the script exits with the new code. A rebuild that succeeds continues as a normal install.

Extra lines above the menu explain some codes: exit 10 (the container probably needs privileged mode or nesting), exit 125/126 (permission problem), a full disk (with the current disk size), and a missing command (its name).

Two dev mode flags skip the menu: keep leaves the container untouched, breakpoint opens a shell in it.

On Incus, incus/backend.func has its own version of this step.

on_exit

Runs on every exit and keeps the exit code.

WhereExit codeAction
bothanyprints the dev_mode=timing summary; runs apt_conffile_report
both0 after an updatecleanup_lxc, then update_motd_ip if defined
both0 after a release was deployedremoves the .pending markers in $HOME
containernon-zerowrites the .failed flag and .errinfo if the ERR trap did not
container0creates /root/.install-<SESSION_ID>.done
hostnon-zero, nothing reported yetpost_update_to_api "failed" <code>
host0, an install was started but no final status sentpost_update_to_api "aborted" 0 (you backed out of a dialog)
hostnon-zeropulls the install log from the container (ensure_log_on_host); stops the container if the install was still running
bothanyremoves $lockfile if set

Signals

SignalHandlerBehaviour
Ctrl-C (SIGINT)on_interruptHost reports aborted with code 130; container writes its failure flag. A container that is mid-install is stopped. Exit 130
SIGTERMon_terminateThe same with code 143
SIGHUPon_hangupNot an abort, see below

Closing the console

Closing the browser console or losing the SSH session sends SIGHUP. The run is not aborted:

  • on_hangup points stdin at /dev/null and stdout/stderr at the active log, exports _CS_HANGUP=1, and writes The terminal closed; continuing, output follows here. to the log.
  • Programs started through $STD ignore SIGHUP and finish.
  • On the host, lxc-attach dies with the terminal but the install inside the container keeps running. The host then waits for /root/.install-<SESSION_ID>.done or .failed in the container, checking every 15 seconds for up to six hours.
  • If the install then fails, nobody can answer the recovery menu, so the container is kept.

To watch an install whose console you closed:

pct exec <CTID> -- tail -f /root/.install-<SESSION_ID>.log

Ctrl-C does abort.

What is logged where

FileSideContent
/tmp/create-lxc-<SESSION_ID>.loghostBUILD_LOG: host messages and the output of host commands run through $STD
/tmp/pct_create_<CTID>_<timestamp>_<SESSION_ID>.loghostoutput of pct create; appended to the build log
/root/.install-<SESSION_ID>.logcontainerINSTALL_LOG: everything the install script logged
/root/.install-<SESSION_ID>.log.errinfocontainercapture of the failing command
/root/.install-<SESSION_ID>.failedcontainerexit code of a failed install; read and removed by the host
/root/.install-<SESSION_ID>.donecontainerempty marker of a finished install
/root/.install-<SESSION_ID>.pidcontainerPID of the running install script
/tmp/<app>-<CTID>-<SESSION_ID>.loghostcombined log after a failed install
/tmp/.errinfo-<SESSION_ID>hostthe container's capture, pulled for telemetry
/tmp/build-<date>_<time>.logeitherscripts without a build log, such as add-ons
DEBUG_LOGFILEeitherwhen you set this variable, each failure appends a block with timestamp, exit code, line and command

SESSION_ID is the first eight characters of the run's random UUID. With dev_mode=logs the host build log is written to /var/log/community-scripts/ instead of /tmp.

Log lines written by the message functions look like this:

[2026-01-15 10:32:07] [INFO] Installing Dependencies
[2026-01-15 10:32:41] [OK] Installed Dependencies

Rules for script authors

  • Call catch_errors once, where the templates do. Do not add trap … ERR or trap … EXIT of your own.
  • Do not call the telemetry API from an install script.
  • Let commands fail with their real exit status. Use an explicit exit <code> only with a code from the exit-code table that says what happened.
  • Print a msg_error before a deliberate exit; it becomes the failure's message.
  • Use || true for commands that may fail, not set +e.