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_ls.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'tools/fs_ls.sh') diff --git a/tools/fs_ls.sh b/tools/fs_ls.sh index d26132f..e62ee89 100755 --- a/tools/fs_ls.sh +++ b/tools/fs_ls.sh @@ -1,14 +1,32 @@ #!/usr/bin/env bash -set -e +set -uo pipefail # @describe List all files and directories at the specified path. - # @option --path! The path of the directory to list - # @env LLM_OUTPUT=/dev/stdout The output path +OUT="${LLM_OUTPUT:-/dev/stdout}" + +err() { + echo "ERROR: $*" >> "$OUT" + exit 0 +} + main() { - ls -1 "$argc_path" >> "$LLM_OUTPUT" + path="${argc_path:-}" + [[ -z "$path" ]] && err "missing --path" + [[ ! -e "$path" ]] && err "path not found: $path" + [[ ! -d "$path" ]] && err "not a directory: $path" + + # -1A: ein Eintrag pro Zeile, inkl. dotfiles (ohne . und ..) + if ! ls -1A "$path" >> "$OUT" 2>/tmp/fs_ls.err; then + msg="$(cat /tmp/fs_ls.err 2>/dev/null || true)" + err "ls failed for $path: ${msg:-unknown error}" + fi + + exit 0 } eval "$(argc --argc-eval "$0" "$@")" +main + -- cgit v1.2.3