Skip to content

Commit 85553a1

Browse files
committed
feat: Add stacktrace printing function
1 parent b7cac82 commit 85553a1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ I suppose it can look redundant (compared to `if ! fn; then :; fi`), but it can
4747
- `core.err_clear`
4848
- `core.err_exists`
4949

50+
## `stacktrace`
51+
52+
Prints the stack trace. Recommended to use with `core.trap_add`
53+
54+
- `core.stacktrace_print`
55+
5056
Example
5157

5258
```sh

pkg/lib/public/stacktrace.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# shellcheck shell=bash
2+
3+
# @description Prints stacktrace
4+
core.stacktrace_print() {
5+
printf '%s\n' 'Stacktrace:'
6+
7+
local i=
8+
for ((i=0; i<${#FUNCNAME[@]}-1; ++i)); do
9+
printf '%s\n' " in ${FUNCNAME[$i]} (${BASH_SOURCE[$i]}:${BASH_LINENO[$i-1]})"
10+
done; unset -v i
11+
} >&2

0 commit comments

Comments
 (0)