Skip to content

Commit 7d2866f

Browse files
authored
Merge pull request #637 from DannyBen/update/stacktrace
Add `enable_stacktrace` function
2 parents 21a3f44 + b60e218 commit 7d2866f

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

examples/stacktrace/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ examples:
5050
## before running anything else.
5151
##
5252
## You can safely delete this file if you do not need it.
53-
trap 'stacktrace' ERR
54-
set -o errtrace
53+
enable_stacktrace
5554

5655
````
5756

@@ -118,8 +117,8 @@ Examples:
118117

119118
Stack trace:
120119
from ./download:15 in `root_command`
121-
from ./download:254 in `run`
122-
from ./download:260 in `main`
120+
from ./download:260 in `run`
121+
from ./download:266 in `main`
123122

124123

125124
````

examples/stacktrace/src/initialize.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
## before running anything else.
55
##
66
## You can safely delete this file if you do not need it.
7-
trap 'stacktrace' ERR
8-
set -o errtrace
7+
enable_stacktrace

examples/stacktrace/src/lib/stacktrace.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
## Usage:
55
## This function is designed to be called on error.
66
##
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.
7+
## To enable this functionality, call `enable_stacktrace` in your
8+
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
159
##
10+
enable_stacktrace() {
11+
trap 'stacktrace' ERR
12+
set -o errtrace
13+
set -o errexit
14+
}
15+
1616
stacktrace() {
1717
local exit_status="$?"
1818
local i=0

lib/bashly/libraries/libraries.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ stacktrace:
110110
post_install_message: |
111111
The stacktrace function is designed to be called automatically on error.
112112
113-
To enable this functionality, add these lines to your `initialize.sh`:
114-
115-
g`trap 'stacktrace' ERR`
116-
g`set -o errtrace`
113+
To enable this functionality, call g`enable_stacktrace` in your
114+
g`src/initialize.sh`. You may run the following command to add this file:
115+
116+
m`$ bashly add hooks`
117117
118118
strings:
119119
help: Copy an additional configuration file to your project, allowing you to customize all the tips and error strings.

lib/bashly/libraries/stacktrace/stacktrace.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
## Usage:
55
## This function is designed to be called on error.
66
##
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.
7+
## To enable this functionality, call `enable_stacktrace` in your
8+
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
159
##
10+
enable_stacktrace() {
11+
trap 'stacktrace' ERR
12+
set -o errtrace
13+
set -o errexit
14+
}
15+
1616
stacktrace() {
1717
local exit_status="$?"
1818
local i=0

spec/approvals/examples/stacktrace

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ created src/lib/stacktrace.sh
33

44
The stacktrace function is designed to be called automatically on error.
55

6-
To enable this functionality, add these lines to your `initialize.sh`:
6+
To enable this functionality, call enable_stacktrace in your
7+
src/initialize.sh. You may run the following command to add this file:
78

8-
trap 'stacktrace' ERR
9-
set -o errtrace
9+
$ bashly add hooks
1010

1111
+ bashly generate
1212
creating user files in src
@@ -51,5 +51,5 @@ Examples:
5151

5252
Stack trace:
5353
from ./download:15 in `root_command`
54-
from ./download:255 in `run`
55-
from ./download:261 in `main`
54+
from ./download:260 in `run`
55+
from ./download:266 in `main`

0 commit comments

Comments
 (0)