From 27e319f8d1e3a0e8f2db79f62d451768b11d62a3 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Tue, 3 Feb 2026 16:54:42 +0100 Subject: Refined tool return error codes. Now they all return with exit 0 and error messages instead. This prevents early query abortion on fatal errors. --- tools/fs_rm.sh | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'tools/fs_rm.sh') diff --git a/tools/fs_rm.sh b/tools/fs_rm.sh index 9d9386f..e667b0e 100755 --- a/tools/fs_rm.sh +++ b/tools/fs_rm.sh @@ -1,20 +1,36 @@ #!/usr/bin/env bash -set -e +set -uo pipefail # @describe Remove the file or directory at the specified path. - # @option --path! The path of the file or directory to remove - # @env LLM_OUTPUT=/dev/stdout The output path ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" +OUT="${LLM_OUTPUT:-/dev/stdout}" + +err() { + echo "ERROR: $*" >> "$OUT" + exit 0 +} main() { - if [[ -f "$argc_path" ]]; then - "$ROOT_DIR/utils/guard_path.sh" "$argc_path" "Remove '$argc_path'?" - rm -rf "$argc_path" - fi - echo "Path removed: $argc_path" >> "$LLM_OUTPUT" + path="${argc_path:-}" + [[ -z "$path" ]] && err "missing --path" + [[ ! -e "$path" ]] && err "path not found: $path" + + if ! "$ROOT_DIR/utils/guard_path.sh" "$path" "Remove '$path'?" >>"$OUT" 2>&1; then + err "operation cancelled by user" + fi + + if ! rm -rf "$path" 2>/tmp/fs_rm.err; then + msg="$(cat /tmp/fs_rm.err 2>/dev/null || true)" + err "rm failed for $path: ${msg:-unknown error}" + fi + + echo "Path removed: $path" >> "$OUT" + exit 0 } eval "$(argc --argc-eval "$0" "$@")" +main + -- cgit v1.2.3