Skip to content

Commit 7601f7b

Browse files
fix(scripts): wrap python3 call in if-condition to prevent set -e abort
Move the python3 command substitution in resolve_template into an if-condition so that a non-zero exit (e.g. invalid .registry JSON) does not abort the function under set -e. The fallback directory scan now executes as intended regardless of caller errexit settings.
1 parent 74bc9a9 commit 7601f7b

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎scripts/bash/common.sh‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ resolve_template() {
198198
if [ -d "$presets_dir" ]; then
199199
local registry_file="$presets_dir/.registry"
200200
if [ -f "$registry_file" ] && command -v python3 >/dev/null 2>&1; then
201-
# Read preset IDs sorted by priority (lower number = higher precedence)
202-
local sorted_presets
203-
sorted_presets=$(SPECKIT_REGISTRY="$registry_file" python3 -c "
201+
# Read preset IDs sorted by priority (lower number = higher precedence).
202+
# The python3 call is wrapped in an if-condition so that set -e does not
203+
# abort the function when python3 exits non-zero (e.g. invalid JSON).
204+
local sorted_presets=""
205+
if sorted_presets=$(SPECKIT_REGISTRY="$registry_file" python3 -c "
204206
import json, sys, os
205207
try:
206208
with open(os.environ['SPECKIT_REGISTRY']) as f:
@@ -210,17 +212,15 @@ try:
210212
print(pid)
211213
except Exception:
212214
sys.exit(1)
213-
" 2>/dev/null)
214-
local python_rc=$?
215-
if [ $python_rc -eq 0 ] && [ -n "$sorted_presets" ]; then
216-
# python3 succeeded and returned preset IDs — search in priority order
217-
while IFS= read -r preset_id; do
218-
local candidate="$presets_dir/$preset_id/templates/${template_name}.md"
219-
[ -f "$candidate" ] && echo "$candidate" && return 0
220-
done <<< "$sorted_presets"
221-
elif [ $python_rc -eq 0 ]; then
215+
" 2>/dev/null); then
216+
if [ -n "$sorted_presets" ]; then
217+
# python3 succeeded and returned preset IDs — search in priority order
218+
while IFS= read -r preset_id; do
219+
local candidate="$presets_dir/$preset_id/templates/${template_name}.md"
220+
[ -f "$candidate" ] && echo "$candidate" && return 0
221+
done <<< "$sorted_presets"
222+
fi
222223
# python3 succeeded but registry has no presets — nothing to search
223-
:
224224
else
225225
# python3 failed (missing, or registry parse error) — fall back to unordered directory scan
226226
for preset in "$presets_dir"/*/; do

0 commit comments

Comments
 (0)