From dfedc029d1e7e03fc942b32b79f24036e6a910e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20Ta=C5=9Fhan?= Date: Sat, 7 Mar 2026 15:33:47 +0300 Subject: [PATCH] fix: handle empty menu_options in mo purge to prevent unbound variable error (#547) When no artifacts are found during scanning, `menu_options` remains an empty array. With `set -euo pipefail` active, expanding `${menu_options[@]}` on an empty array causes a fatal "unbound variable" error (line 1325). Add an early-return guard after the spinner stops: if no items were found, print a friendly "No artifacts found to purge" message and exit cleanly. Fixes #546 --- lib/clean/project.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/clean/project.sh b/lib/clean/project.sh index d6158b4..c1a9ee7 100644 --- a/lib/clean/project.sh +++ b/lib/clean/project.sh @@ -1310,6 +1310,14 @@ clean_project_artifacts() { if [[ -t 1 ]]; then stop_inline_spinner fi + # Exit early if no artifacts were found to avoid unbound variable errors + # when expanding empty arrays with set -u active. + if [[ ${#menu_options[@]} -eq 0 ]]; then + echo "" + echo -e "${GRAY}No artifacts found to purge${NC}" + printf '\n' + return 0 + fi # Set global vars for selector export PURGE_CATEGORY_SIZES=$( IFS=,