Files
openclaw-backups/scripts/with-error-log.sh

28 lines
513 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 1 ]; then
echo "Usage: with-error-log.sh <command...>"
exit 2
fi
cmd="$*"
set +e
output=$(eval "$cmd" 2>&1)
code=$?
set -e
if [ "$code" -ne 0 ]; then
/home/openclaw/.openclaw/workspace/scripts/log-error.sh \
"Command failed: $cmd" \
"$output" \
"Captured via with-error-log.sh wrapper" \
"high" \
"infra" >/dev/null || true
echo "$output"
echo "(error auto-logged to .learnings/ERRORS.md)" >&2
exit "$code"
fi
echo "$output"