November 1, 2026 路 #46
The failure that local swallowed
The token fetch fails, yet the script keeps going and calls the API with an empty token. Which line hides the error?
#!/usr/bin/env bash
set -euo pipefail
fetch_token() {
local token=$(vault read -field=token secret/ci)
curl -fsS -H "Authorization: Bearer ${token}" https://api.internal/deploy
}
fetch_tokenNext puzzle in UTC
One try. The first answer sticks.
How to fix it
local is a builtin with its own exit status. local x=$(cmd) succeeds even when cmd fails, so set -e sees 0. Declare first, then assign.
set -e reacts to the status of a simple command. In local token=$(vault read ...) the command is local, which succeeds as long as the assignment is valid. The command substitution fails, its status is discarded, and token is empty. set -u does not help either, because the variable is set, just to an empty string. The same trap applies to export and declare.
ShellCheck flags this as SC2155.
Fix
fetch_token() {
local token
token=$(vault read -field=token secret/ci)
curl -fsS -H "Authorization: Bearer ${token}" https://api.internal/deploy
}
A plain assignment returns the status of the command substitution, so set -e stops the script. Add : "${token:?empty token}" if an empty but successful read is also possible.