vim-plugins icon indicating copy to clipboard operation
vim-plugins copied to clipboard

Bash-Support: parce call stack on error

Open bam80 opened this issue 6 years ago • 8 comments

We already can jump to error place in the script. But it would be fine if we could have also call stack in QuickFix window. That way we could jump on the stack even without debugger. The call stack can be traced out with caller builtin, using trap on error. We just need to tune 'errorformat' to parse it properly.

bam80 avatar Jan 16 '19 16:01 bam80

This is not really my area of expertise, but I guess the use case would be like this:

Backtrace () {
  i=1
  while caller $i
  do
    i=$((i+1))
  done
}
trap 'Backtrace' EXIT ERR

Then you get a trace like:

test.sh|33| MY_UNBOUND_VARIABLE: unbound variable
|| 39 bbb /home/wolfgang/path/test.sh
|| 42 main /home/wolfgang/path/test.sh

WolfgangMehner avatar Jan 16 '19 21:01 WolfgangMehner

@WolfgangMehner thanks, could you please attach the test script here?

bam80 avatar Jan 16 '19 22:01 bam80

My point was mainly about the format we need to be able to pass. I guessed the following format:

<line-number> <function-name> <file-name>

Here is the full script (can not upload *.sh for some reason):

trap_test.txt

WolfgangMehner avatar Jan 17 '19 18:01 WolfgangMehner

Extended the error format for testing: https://github.com/WolfgangMehner/vim-plugins/tree/bashsupport-trace-test

WolfgangMehner avatar Jan 17 '19 18:01 WolfgangMehner

@WolfgangMehner Thanks for your kind. ~~The links is broken~~

bam80 avatar Jan 17 '19 18:01 bam80

Can you find the branch "bashsupport-trace-test" anyway?

WolfgangMehner avatar Jan 17 '19 19:01 WolfgangMehner

I'm not sure I fully understood your last comment, sorry. Which link or links is broken?

WolfgangMehner avatar Feb 01 '19 17:02 WolfgangMehner

Sorry, my fault - I just didn't catch the link points to the other branch.

bam80 avatar Feb 01 '19 17:02 bam80