File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,19 @@ settings:
102
102
- source : " settings/settings.yml"
103
103
target : " settings.yml"
104
104
105
+ stacktrace :
106
+ help : Add a function that shows stacktrace on error.
107
+ files :
108
+ - source : " stacktrace/stacktrace.sh"
109
+ target : " %{user_lib_dir}/stacktrace.%{user_ext}"
110
+ post_install_message : |
111
+ The stacktrace function is designed to be called automatically on error.
112
+
113
+ To enable this functionality, add these lines to your `initialize.sh`:
114
+
115
+ g`trap 'stacktrace' ERR`
116
+ g`set -o errtrace`
117
+
105
118
strings :
106
119
help : Copy an additional configuration file to your project, allowing you to customize all the tips and error strings.
107
120
files :
Original file line number Diff line number Diff line change
1
+ # # Stack trace functions [@bashly-upgrade stacktrace]
2
+ # # This file is a part of Bashly standard library
3
+ # #
4
+ # # Usage:
5
+ # # This function is designed to be called on error.
6
+ # #
7
+ # # To enable this functionality, add these lines to your `src/initialize.sh`
8
+ # # file (Run `bashly add hooks` to add this file):
9
+ # #
10
+ # # trap 'stacktrace' ERR
11
+ # # set -o errtrace
12
+ # #
13
+ # # Note that this functionality also requires `set -e`, which is enabled by
14
+ # # default in bashly generated scripts.
15
+ # #
16
+ stacktrace () {
17
+ local i=0
18
+ local caller_output line func file
19
+
20
+ echo " ${BASH_SOURCE[0]} :${BASH_LINENO[0]} in \` ${FUNCNAME[1]} \` : $BASH_COMMAND "
21
+ echo " Stack trace:"
22
+ while caller_output=" $( caller $i ) " ; do
23
+ read -r line func file <<< " $caller_output"
24
+ echo -e " \tfrom ${file} :${line} in \` $func \` "
25
+ i=$(( i + 1 ))
26
+ done
27
+ exit 1
28
+ } >&2
You can’t perform that action at this time.
0 commit comments