Skip to content

Commit 4e8b1bb

Browse files
authored
fix(cli): hard-fail invalid WHEELS_FRAMEWORK_PATH instead of silent fallback (#2215) (#2222)
When WHEELS_FRAMEWORK_PATH was set but pointed at a non-existent directory, resolveFrameworkSource() appended the path to the search list and fell through to tier 2/3 auto-discovery. The user's explicit override was silently ignored — a typo or stale path could resolve to a surprising framework version instead of failing loudly. Throw Wheels.FrameworkPathInvalid when the override is set but directoryExists() is false. Picocli maps this to exit code 1 (same mechanism as #2216). Error message echoes the bad path and suggests both remedies (unset or point at a valid source). Moved the `override` var out of the try so the throw isn't swallowed by the catch-all that guards getenv() availability. Extended test-new-exit-codes.sh with a GH #2215 section: invalid path must exit non-zero, error must echo the bad path, no partial scaffold. Verified RED pre-fix (exit 0, silent fallback) and GREEN post-fix.
1 parent f4f9bfe commit 4e8b1bb

2 files changed

Lines changed: 67 additions & 13 deletions

File tree

cli/lucli/Module.cfc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,17 +3484,30 @@ component extends="modules.BaseModule" {
34843484
variables.frameworkSearchPaths = [];
34853485

34863486
// 1. Explicit override via environment variable — highest priority.
3487+
// When the user sets WHEELS_FRAMEWORK_PATH they are giving an
3488+
// imperative "use this" — if the path doesn't exist, hard-fail
3489+
// rather than silently falling through to auto-discovery (a stale
3490+
// or typo'd path could otherwise resolve to a surprising framework
3491+
// version). See GH #2215.
3492+
var override = "";
34873493
try {
34883494
var javaSystem = createObject("java", "java.lang.System");
3489-
var override = javaSystem.getenv("WHEELS_FRAMEWORK_PATH");
3490-
if (!isNull(override) && len(trim(override))) {
3491-
arrayAppend(variables.frameworkSearchPaths, override & " (from $WHEELS_FRAMEWORK_PATH)");
3492-
if (directoryExists(override)) {
3493-
return override;
3494-
}
3495+
var envValue = javaSystem.getenv("WHEELS_FRAMEWORK_PATH");
3496+
if (!isNull(envValue)) {
3497+
override = envValue;
34953498
}
34963499
} catch (any e) {
3497-
// Ignore — env var not accessible in this runtime.
3500+
// Env var not accessible in this runtime — treat as unset.
3501+
}
3502+
if (len(trim(override))) {
3503+
arrayAppend(variables.frameworkSearchPaths, override & " (from $WHEELS_FRAMEWORK_PATH)");
3504+
if (directoryExists(override)) {
3505+
return override;
3506+
}
3507+
throw(
3508+
type="Wheels.FrameworkPathInvalid",
3509+
message="WHEELS_FRAMEWORK_PATH is set to '#override#' but that directory does not exist. Unset the variable to fall back to auto-discovery, or point it at a valid vendor/wheels/ source."
3510+
);
34983511
}
34993512

35003513
// 2. Project root (e.g. user ran `wheels new` from inside an existing

cli/lucli/tests/test-new-exit-codes.sh

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env bash
2-
# Regression test for GH #2211 and GH #2214: `wheels new` must exit
3-
# non-zero on every user-facing error path, not silently succeed.
2+
# Regression tests for wheels new exit-code contracts.
43
#
5-
# Coverage:
6-
# - #2211: framework source not found
7-
# - #2214: target directory already exists
8-
# - #2214: app name missing (args supplied but none parsed as appname)
4+
# GH #2211 — framework source not found anywhere must exit non-zero
5+
# GH #2215 — explicit WHEELS_FRAMEWORK_PATH pointing at a non-existent
6+
# directory must hard-fail (not silently fall through to
7+
# auto-discovery)
8+
# GH #2214 — target directory already exists must exit non-zero
9+
# GH #2214 — app name missing (args supplied but none parsed) must exit non-zero
910
#
1011
# Prerequisites:
1112
# - wheels binary on PATH
@@ -68,6 +69,46 @@ else
6869
fail "partial fixture/ directory left behind"
6970
fi
7071

72+
echo ""
73+
echo "=== GH #2215: invalid WHEELS_FRAMEWORK_PATH must hard-fail ==="
74+
echo ""
75+
76+
# Fresh subdir so a leftover fixture/ from case #2211 doesn't poison the check.
77+
SUBDIR="$TMPDIR/case-2215"
78+
mkdir -p "$SUBDIR"
79+
cd "$SUBDIR"
80+
81+
BAD_PATH="$SUBDIR/does-not-exist/vendor/wheels"
82+
export WHEELS_FRAMEWORK_PATH="$BAD_PATH"
83+
84+
OUT=$(wheels new fixture --no-open-browser 2>&1)
85+
CODE=$?
86+
87+
echo "--- output (last 8 lines) ---"
88+
echo "$OUT" | tail -8
89+
echo "--- exit code: $CODE ---"
90+
echo ""
91+
92+
if [ "$CODE" -ne 0 ]; then
93+
pass "wheels new exits non-zero when WHEELS_FRAMEWORK_PATH is invalid"
94+
else
95+
fail "wheels new exited 0 despite invalid WHEELS_FRAMEWORK_PATH (GH #2215)"
96+
fi
97+
98+
if echo "$OUT" | grep -qF "$BAD_PATH"; then
99+
pass "error message echoes the invalid path"
100+
else
101+
fail "error message does not mention the invalid path"
102+
fi
103+
104+
if [ ! -d "$SUBDIR/fixture" ]; then
105+
pass "no partial fixture/ directory left behind (case 2215)"
106+
else
107+
fail "partial fixture/ directory left behind (case 2215)"
108+
fi
109+
110+
unset WHEELS_FRAMEWORK_PATH
111+
71112
echo ""
72113
echo "=== GH #2214: wheels new target-directory-exists regression ==="
73114

0 commit comments

Comments
 (0)