fix: prevent set -e crash when yq exits non-zero on IONOS

Two issues on IONOS shared hosting (very low ulimit -u):

1. bash 4.4+ propagates the exit code of command substitutions through
   `local var=$(cmd)`. When yq crashes (exit 2) the assignment itself
   returns 2, and set -e kills the script before any log message appears.
   Fixed by adding `|| return 0` to the yq wrapper so it always exits 0.

2. All ref_count comparisons checked for "null"/"0" but not for empty
   string. A yq call that produces no stdout (crashed but returned 0)
   leaves ref_count="", which neither guard caught — the arithmetic loop
   `i < ref_count` silently treated "" as 0 and skipped all references.
   Fixed by adding `[[ -z "$ref_count" ]]` to every ref_count guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 23:10:55 +02:00
parent 90f7b58a53
commit d2bff00ee2
+9 -8
View File
@@ -163,9 +163,10 @@ load_env_vars() {
fi
}
# Wrapper to limit Go thread usage on hosts with low ulimit -u (e.g. IONOS shared hosting)
# Wrapper to limit Go thread usage on hosts with low ulimit -u (e.g. IONOS shared hosting).
# Always returns 0 so set -e doesn't propagate a yq crash through `local var=$(yq ...)`.
yq() {
GOMAXPROCS=1 GOGC=off command yq "$@"
GOMAXPROCS=1 GOGC=off command yq "$@" || return 0
}
# Check if yq is installed
@@ -544,7 +545,7 @@ find_ancestor_into() {
if [[ -f "$config_to_check" ]]; then
# Get count of references
local ref_count=$(yq eval '.references | length' "$config_to_check" 2>/dev/null)
if [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
if [[ -n "$ref_count" ]] && [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
# Check each reference
for ((i = 0; i < ref_count; i++)); do
local ref_data=$(parse_reference "$config_to_check" "$i")
@@ -601,7 +602,7 @@ install_references() {
# Count references
local ref_count=$(yq eval '.references | length' "$config_file" 2>/dev/null)
if [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
if [[ -z "$ref_count" ]] || [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
log_info "No references to install"
return 0
fi
@@ -670,7 +671,7 @@ build_reference_tree() {
# Count references
local ref_count=$(yq eval '.references | length' "$config_file" 2>/dev/null)
if [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
if [[ -z "$ref_count" ]] || [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
return 0
fi
@@ -832,7 +833,7 @@ list_libs() {
# Check if there are any references
local ref_count=$(yq eval '.references | length' "$ARTY_CONFIG_FILE" 2>/dev/null)
if [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
if [[ -z "$ref_count" ]] || [[ "$ref_count" == "null" ]] || [[ "$ref_count" == "0" ]]; then
# No references defined, check for installed libraries
local libs_dir="${ARTY_LIBS_DIR:-${ARTY_HOME:-$PWD/.arty}/libs}"
if [[ ! -d "$libs_dir" ]] || [[ -z "$(ls -A "$libs_dir" 2>/dev/null)" ]]; then
@@ -2023,7 +2024,7 @@ main() {
# Show tree after installation if successful and arty.yml exists and has references
if [[ $install_result -eq 0 ]] && [[ -f "$ARTY_CONFIG_FILE" ]]; then
local ref_count=$(yq eval '.references | length' "$ARTY_CONFIG_FILE" 2>/dev/null)
if [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
if [[ -n "$ref_count" ]] && [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
echo
log_success "Installation complete!"
list_libs
@@ -2036,7 +2037,7 @@ main() {
# Show tree after installation if successful and arty.yml exists and has references
if [[ $install_result -eq 0 ]] && [[ -f "$ARTY_CONFIG_FILE" ]]; then
local ref_count=$(yq eval '.references | length' "$ARTY_CONFIG_FILE" 2>/dev/null)
if [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
if [[ -n "$ref_count" ]] && [[ "$ref_count" != "null" ]] && [[ "$ref_count" != "0" ]]; then
echo
log_success "Dependencies installed!"
list_libs