-
-
Notifications
You must be signed in to change notification settings - Fork 93
Add stacktrace
standard library
#635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Nothing against it! 👍
I didn't face any situation of the trap being executed by a "normal" bashly behavior. Specifically about argument handling, I've tested here and all situations were smoothly handled by bashly's To do the tests I installed the stacktrace in the See the tests here
|
@pcrockett do you wish to review this before I merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks neat. I haven't read the full discussion, but I assume this is pretty thoroughly tested by @meleu over the course of time. Maybe I'll upgrade my tools to use it as well after the next release, see if I can find ways to break it. 👍
Oh, might consider mentioning the strict setting as an alternative to adding |
I thought about it, but decided to separate - since you still have to add the |
I've just noticed something while using BATS for unit testing here. No actions to be taken on bashly side, I'm just sharing a recent finding TL;DRNothing breaks, just the failing test output becomes more "polluted" when the script is sourced. Solution: disable the trap right after sourcing the script ( long versionI usually do unit testing by sourcing the final script and then in each test I call the individual function under test. I noticed that with stacktrace enabled, the test failure output becomes polluted. examplesHere are two examples adapted from a real test (ignore the test logic and focus on the output). keeping the
|
I could have guessed that trapping error might cause issues in some cases. |
I think I'll stick with this approach for now and see if it works fine: Trap # initialize.sh
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
trap 'stacktrace' ERR
fi |
Yup. Anything that works for your use case and audience is valid. |
@DannyBen one thing that just came to my mind: The official enable_stacktrace() {
trap 'stacktrace' ERR
set -o errtrace
} That would be similar to what we did with enable_auto_colors. I this allows the # src/initialize.sh
enable_auto_colors
is_sourced || enable_stacktrace
# whatever... What do you think? Also, a post-install hook could give instructions similar to what we do for colors: |
Lovely. One thing that bothers me, is the Thoughts? |
The first option makes more sense to me. As we are explicitly adding a hook named initialize. The second option gives an impression that I'm adding a library named initialize. |
Still about refining the stacktrace... It's quite usual for bash coders to run The thing is that the xtrace's output for This is how I solved it: stacktrace() {
local exit_status="$?"
set +x # 👈 MUST be after exit_status assignment
# ...
} It's important to disable Do you think it makes sense to make this "official"? One thing I considered: as the |
This seems like an over-intervention to me. I feel this falls into the "personal habit" category. Don't forget that all libraries are dumped into userland for this reason exactly - they serve as a good basis for you to edit if you need to. I do not feel that we need to anticipate the use of |
As discussed in #601