FoolDev Claude Opus 4.7 commited on
Commit
385ed94
·
1 Parent(s): aaef90f

fix(heal-hf): give an actionable error when the tag isn't pulled

Browse files

Reproduced this session: `make heal-hf` against an empty ollama
store (after a clean wipe) printed only

[*] tag: hf.co/FoolDev/Thanatos-27B:Q4_K_M
[*] store: /home/fool/.ollama/models
make: *** [Makefile:47: heal-hf] Error 1

and exited 1. The intended "could not resolve model blob for tag
'...'. Is the tag pulled? Try: ollama pull <tag>" hint never
appeared.

Root cause is a set-e + pipefail interaction. The blob-locator
line was

MODEL_BLOB="$(ollama show --modelfile "${TAG}" 2>/dev/null | awk ...)"

When the tag isn't pulled, `ollama show` exits 1, `pipefail`
propagates the non-zero exit code through the pipeline (awk's
own 0 doesn't mask it), and `set -e` terminates the script on
the assignment before the explicit `[[ -z "${MODEL_BLOB}" ]]`
check below it ever runs.

Fixed by splitting the assignment so set -e doesn't see a failed
pipeline:

MODEL_BLOB=""
if MODELFILE_OUT="$(ollama show --modelfile "${TAG}" 2>/dev/null)"; then
MODEL_BLOB="$(awk '/^FROM[[:space:]]/ {print $2; exit}' <<<"${MODELFILE_OUT}")"
fi
if [[ -z "${MODEL_BLOB}" || ! -f "${MODEL_BLOB}" ]]; then
red "[!] could not resolve model blob for tag '${TAG}'."
red " Is the tag pulled? Try: ollama pull ${TAG}"
exit 1
fi

The `if cmd; then` form takes the false branch on failure without
tripping set -e — the long-standing shell idiom for "test this
command without aborting on failure." Behavior on the happy path
(tag is pulled, ollama show succeeds) is unchanged.

Added a load-bearing comment block explaining the gotcha so the
next reader doesn't "simplify" it back to the broken direct
substitution form.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (2) hide show
  1. CHANGELOG.md +13 -0
  2. scripts/heal_hf_pull.sh +14 -1
CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and documentation**, not the underlying base model.
7
 
8
  ## [Unreleased]
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ### Added
11
  - `scripts/heal_hf_pull.sh` now validates the rewritten manifest by
12
  running `ollama show <tag>` immediately after the atomic mv into
 
7
 
8
  ## [Unreleased]
9
 
10
+ ### Fixed
11
+ - `scripts/heal_hf_pull.sh` silent-exit when the target tag isn't
12
+ pulled. The blob-locator line was
13
+ `MODEL_BLOB="$(ollama show --modelfile "${TAG}" 2>/dev/null | awk ...)"`;
14
+ under `set -e + pipefail`, an unpulled tag makes `ollama show`
15
+ exit non-zero, pipefail propagates the non-zero through the
16
+ pipeline, and set -e terminates the script before the explicit
17
+ `[[ -z "${MODEL_BLOB}" ]]` check ever runs. The user saw only
18
+ `make: *** [Makefile:47: heal-hf] Error 1` with no clue what
19
+ was wrong. Refactored to use an `if MODELFILE_OUT=...; then`
20
+ form, which takes the false branch on failure without tripping
21
+ set -e. The "tag not pulled?" hint now fires as intended.
22
+
23
  ### Added
24
  - `scripts/heal_hf_pull.sh` now validates the rewritten manifest by
25
  running `ollama show <tag>` immediately after the atomic mv into
scripts/heal_hf_pull.sh CHANGED
@@ -56,7 +56,20 @@ done
56
  # (hf.co's 307 lets `Thanatos-27B` and `thanatos-27b` both resolve to the
57
  # canonical repo, and ollama stores the manifest under whichever case
58
  # was first registered).
59
- MODEL_BLOB="$(ollama show --modelfile "${TAG}" 2>/dev/null | awk '/^FROM[[:space:]]/ {print $2; exit}')"
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  if [[ -z "${MODEL_BLOB}" || ! -f "${MODEL_BLOB}" ]]; then
61
  red "[!] could not resolve model blob for tag '${TAG}'."
62
  red " Is the tag pulled? Try: ollama pull ${TAG}"
 
56
  # (hf.co's 307 lets `Thanatos-27B` and `thanatos-27b` both resolve to the
57
  # canonical repo, and ollama stores the manifest under whichever case
58
  # was first registered).
59
+ #
60
+ # The `if MODELFILE_OUT=...; then` form rather than a direct command
61
+ # substitution is load-bearing: under `set -e + pipefail`, a bare
62
+ # `MODEL_BLOB="$(ollama show ... | awk ...)"` silently terminates
63
+ # the script when the tag isn't pulled (ollama show exits non-zero
64
+ # -> pipefail propagates -> set -e exits the script before the
65
+ # explicit `[[ -z "${MODEL_BLOB}" ]]` check below ever runs). The
66
+ # `if` form takes the false branch on failure without tripping
67
+ # set -e, so the user gets the actionable error instead of a silent
68
+ # `make: *** [Makefile:N: heal-hf] Error 1`.
69
+ MODEL_BLOB=""
70
+ if MODELFILE_OUT="$(ollama show --modelfile "${TAG}" 2>/dev/null)"; then
71
+ MODEL_BLOB="$(awk '/^FROM[[:space:]]/ {print $2; exit}' <<<"${MODELFILE_OUT}")"
72
+ fi
73
  if [[ -z "${MODEL_BLOB}" || ! -f "${MODEL_BLOB}" ]]; then
74
  red "[!] could not resolve model blob for tag '${TAG}'."
75
  red " Is the tag pulled? Try: ollama pull ${TAG}"