aboutsummaryrefslogtreecommitdiffstats
path: root/tools/fs_patch.sh
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2026-02-09 02:19:05 +0100
committerLeonard Kugis <leonard@kug.is>2026-02-09 02:19:05 +0100
commit5bb4a3038a0a638359d366f2934a7bb6a8d5bd6b (patch)
treed78274f7f54cae246980fb8eed45e2e8296943f0 /tools/fs_patch.sh
parent27e319f8d1e3a0e8f2db79f62d451768b11d62a3 (diff)
downloadllm-functions-docker-5bb4a3038a0a638359d366f2934a7bb6a8d5bd6b.tar.gz
fs_patch, web_search: Never exit with exit code != 0
Print error instead
Diffstat (limited to 'tools/fs_patch.sh')
-rwxr-xr-xtools/fs_patch.sh35
1 files changed, 24 insertions, 11 deletions
diff --git a/tools/fs_patch.sh b/tools/fs_patch.sh
index 84ae49e..2d9d7e4 100755
--- a/tools/fs_patch.sh
+++ b/tools/fs_patch.sh
@@ -2,8 +2,9 @@
set -uo pipefail
# @describe Apply a patch to a file at the specified path.
-# @option --path! The path of the file to apply to
-# @option --contents! The patch to apply to the file
+# NOTE: This tool NEVER exits with non-zero (even on missing args). It reports errors in output.
+# @option --path The path of the file to apply to
+# @option --contents The patch to apply to the file
# @env LLM_OUTPUT=/dev/stdout The output path
ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
@@ -18,16 +19,16 @@ main() {
path="${argc_path:-}"
patch="${argc_contents:-}"
- [[ -z "$path" ]] && err "missing --path"
- [[ -z "$patch" ]] && err "missing --contents"
- [[ ! -e "$path" ]] && err "file not found: $path"
- [[ ! -f "$path" ]] && err "not a regular file: $path"
- [[ ! -r "$path" ]] && err "file not readable: $path"
+ [[ -z "${path}" ]] && err "missing --path"
+ [[ -z "${patch}" ]] && err "missing --contents"
+ [[ ! -e "${path}" ]] && err "file not found: ${path}"
+ [[ ! -f "${path}" ]] && err "not a regular file: ${path}"
+ [[ ! -r "${path}" ]] && err "file not readable: ${path}"
new_contents=""
if ! new_contents="$(awk -f "$ROOT_DIR/utils/patch.awk" "$path" <(printf "%s" "$patch") 2>/tmp/fs_patch.err)"; then
msg="$(cat /tmp/fs_patch.err 2>/dev/null || true)"
- err "patch apply failed for $path: ${msg:-unknown error}"
+ err "patch apply failed for ${path}: ${msg:-unknown error}"
fi
# Diff in Tool-Output schreiben (damit das LLM es sieht)
@@ -40,13 +41,25 @@ main() {
if ! printf "%s" "$new_contents" > "$path" 2>/tmp/fs_patch_write.err; then
msg="$(cat /tmp/fs_patch_write.err 2>/dev/null || true)"
- err "failed to write patched file $path: ${msg:-unknown error}"
+ err "failed to write patched file ${path}: ${msg:-unknown error}"
fi
- echo "The patch applied to: $path" >> "$OUT"
+ echo "The patch applied to: ${path}" >> "$OUT"
exit 0
}
-eval "$(argc --argc-eval "$0" "$@")"
+# IMPORTANT: Do not let argc failures abort the script.
+# - remove "set -e"
+# - and swallow argc's non-zero return
+eval "$(argc --argc-eval "$0" "$@" 2>/tmp/argc_fs_patch.err || true)"
+
+# If argc itself failed (e.g. parse error), report but still exit 0
+if [[ -s /tmp/argc_fs_patch.err ]]; then
+ echo "ERROR: argc parse failed: $(cat /tmp/argc_fs_patch.err)" >> "$OUT"
+ rm -f /tmp/argc_fs_patch.err
+ exit 0
+fi
+rm -f /tmp/argc_fs_patch.err
+
main