Closed complyue closed 4 years ago
oops, Travis failed, but my local tests all passed. help?
I am still not sure how exactly how error handling should be improved but I feel like adding a boolin options to main calling functions is not the best path to take.
I was generally thinking there might be a way to improve the VM error but have not taking the time to think about it much. https://github.com/mattn/anko/blob/master/vm/vm.go#L64-L66
Are there any examples of other programs using StackTrace?
I am still not sure how exactly how error handling should be improved but I feel like adding a boolin options to main calling functions is not the best path to take.
Yes, I agree. For better API design there are better ways, I looked at https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis and personally feel config struct described there may be enough, or functional options may be the way to go. But that's a decision for Anko authors to make, I don't even know if there will be one another option to be added, and without more and more options to add, it's no hurry to make any decision.
I was generally thinking there might be a way to improve the VM error but have not taking the time to think about it much. https://github.com/mattn/anko/blob/master/vm/vm.go#L64-L66
I'm not sure if Anko has already supported recursive function definition, if a func defined by script can not call itself recursively, and mutual recursion neither supported, I do think a line number and script file name is enough. But if recursion is well supported and meant to be used intensively, I suppose script authors will be needing stacktraces on errors to help debug script problems.
And I suggest goroutine stack trace and Anko script error (with stack frames or not) better be considered separate things, in either case. The former is mainly to track down problems in scripted pieces written in Go, not the scripting part.
Are there any examples of other programs using StackTrace?
I don't know specific open code for that, but I think few programs will be parsing stack frames then do sth, most would be implicitly benefited from the full stacktrace printed out on panic or SIGQUIT.
Also can look at:
@complyue No longer going to do this? Close this?
sure, let's close this for now.
In running scripts, Anko will capture panics unless run in debug mode.
My case is that I wrote a framework, with some library functions meant to be called by application code, the applications are supposed to be written in part Go , part Anko script. And the framework accepts scripts from elsewhere, and run them with an Anko env. While the applications may be mis-using the library functions sometimes, in which case a library function will panic with error description. And since the scripts come from many where and executes with great concurrency, just the error description is far from adequate to locate which application and which part of it caused the error, full stack trace is much desired for trouble shooting few bugs among massive concurrent tasks running smoothly in a production system, where I can't put Anko in debug mode.
What I'm suggesting in this PR is that an
Unsafe
version ofExecuteContext
andRunContext
be added, with an option argumentcapturePanic bool
, to specify whether the caller intends to capture panics from the script code by itself. And existingExecuteContext
andRunContext
stay the same behavior wrt the ${ANKO_DEBUG} environment variable.Another option may be to coerce whatever captured into
error
type forrunInfo.err
in more sophisticated ways, I would do that by a customerrors
module in each of my Go projects, like:But I think that's only a temporary solution before the std
errors
module provides richer info ultimately, so am not willing to persuade others to do alike.