Skip to content

Commit 259d326

Browse files
committed
Do not let ensure_docker die in the ERR trap when nobody can answer
ensure_docker read the "Install Docker now?" answer straight off stdin with no guard. Headless that read hits EOF and returns 1, and since catch_errors turns on errexit with an ERR trap, the script died reporting a bare "exit code 1" instead of the "Docker is required" message on the next line. The decision is unchanged -- anything but yes still aborts with 254 -- but it now says that the run was unattended and what to do about it, rather than looking like a random failure.
1 parent 0197438 commit 259d326

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/runtime.func

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,18 @@ ensure_docker() {
181181
fi
182182

183183
msg_warn "Docker is not installed."
184+
# An unguarded read is worse than useless headless: at EOF it returns 1, and
185+
# catch_errors has errexit plus an ERR trap, so the script died reporting
186+
# "exit code 1" instead of the message two lines down. The default is
187+
# unchanged -- anything but yes still aborts -- it just says why now.
188+
local install_docker_prompt=""
189+
if _docker_is_noninteractive; then
190+
msg_error "Docker is required for ${APP:-this script}, and this run is unattended."
191+
msg_custom "💡" "${YW:-}" "Install Docker first, or re-run interactively to be asked."
192+
exit 254
193+
fi
184194
echo -n "${TAB:- }Install Docker now? (y/N): "
185-
local install_docker_prompt
186-
read -r install_docker_prompt
195+
read -r install_docker_prompt || install_docker_prompt=""
187196
if [[ ! "${install_docker_prompt,,}" =~ ^(y|yes)$ ]]; then
188197
msg_error "Docker is required for ${APP:-this script}. Exiting."
189198
exit 254

0 commit comments

Comments
 (0)