feat: panic backtraces

This commit is contained in:
2026-06-02 23:09:17 +02:00
parent e05ade1a30
commit 9ddfb7b74b
2 changed files with 22 additions and 3 deletions
+6 -3
View File
@@ -4,7 +4,7 @@ std::bootstrap() {
declare -g STD_VERSION=$1
}
std::bootstrap 0.1.2
std::bootstrap 0.1.3
INTERPRETER=$(ps -p $$ | awk '$1 != "PID" {print $(NF)}')
: "${INTERPRETER:=bash}"
@@ -134,8 +134,11 @@ std::mod::source() {
elif ! [[ "$joined_path" == *.sh ]]; then
std::mod::source "$module_name" "$import_path.sh"
else
echo "$joined_path path not found"
std::panic "$joined_path path not found"
if command -v std::panic &>/dev/null; then
std::panic "$joined_path path not found"
else
echo "$joined_path path not found"
fi
fi
# condition
+16
View File
@@ -6,6 +6,20 @@ std::wprintln() {
printf "\033[1;33m%s\033[0m\n" "$*" >&2
}
std::backtrace() {
if ! std::interpreter::is-bash; then
std::eprintln "Backtraces are only available for bash"
exit 1
fi
std::eprintln
std::eprintln $'\033[4m'"Backtrace:"
for i in "${!FUNCNAME[@]}"; do
std::eprintln " ${FUNCNAME[$i]} called at ${BASH_SOURCE[$i]}:${BASH_LINENO[$i - 1]}"
done
}
std::panic() {
if [ -n "${1:-}" ]; then
local arg1=$1
@@ -15,6 +29,8 @@ std::panic() {
std::eprintln "code panicked"
fi
[ -z "${SH_BACKTRACE:-}" ] || std::backtrace
exit 1
}