-
Notifications
You must be signed in to change notification settings - Fork 163
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
Enable JupyterKernel to print traceback on error #2530
Conversation
This builds on #2529. |
This seemed to me to be the easiest way to get this done for now. Another idea would be to have
I can't imagine a situation where a traceback would not be helpful. Maybe I'm suffering a spontaneous lack of imagination though. :) |
I think its a bad idea to have a variable for specific What's wrong with a variable that enables or disables printing of backtraces? I struggle imagining a case in which one'd want to suppress backtraces, but then at least one could. I also agree that |
Uhm, I think And I also I have quite some custom code which relies on the current behavior of Don't get me wrong, I'd survive if this changed, but I am not convinced by the argument given here that this is necessary or even that desirable, nor do I agree that Can't you, instead of changing this code, instead install a custom OnBreak := function()
ErrorLevel := ErrorLevel-1;
ErrorLVars := errorLVars;
if ErrorLevel = 0 then LEAVE_ALL_NAMESPACES(); fi;
JUMP_TO_CATCH(0);
end; That said, I'd generally agree that |
lib/error.g
Outdated
if IsBound(IsRunningJupyterKernel) then | ||
location := CURRENT_STATEMENT_LOCATION(context); | ||
if location <> fail then | ||
PrintTo(GAP_ERROR_STREAM, " at ", location[1], ":", location[2]); |
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.
This causes the test suite to fail, as GAP_ERROR_STREAM
is not defined. Perhaps you meant "*errout*"
?
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.
he did mean GAP_ERROR_STREAM
, because I used that global variable in my prototype code for error printing in the JupyterKernel
package.
Whether it's useful to use GAP_ERROR_STREAM
over "*errout*"
is debatable, as long as it's search-and-replaceable, either is fine for me, with preference for "*errout*"
because its consistent with the remainder of the codebase.
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.
Then this pull request is incomplete, as GAP_ERROR_STREAM
is not defined. It cannot be merged until this is resolved, either by defining GAP_ERROR_STREAM
, or by not using it.
Sorry for being absent. I neglected to mention that this needs #2529 to be merged and that printing tracebacks while testing would lead to "false errors" when e.g. changing filenames. wrt this PR: @fingolfin You mean when running a JupyterKernel we don't use More general (I made separate issues for these points): I think with a global variable |
77978f8
to
da9690b
Compare
Codecov Report
@@ Coverage Diff @@
## master #2530 +/- ##
==========================================
- Coverage 74.46% 74.46% -0.01%
==========================================
Files 481 481
Lines 242743 242743
==========================================
- Hits 180770 180769 -1
- Misses 61973 61974 +1
|
@fingolfin I made it work with your suggestion.
|
I'm not sure whether making |
This makes it possible for the JupyterKernel package to override the function OnBreak. Namely `errorLVars` becomes the global variable `ErrorLVarsOld` so that the alternative OnBreak function can also read from and write to it.
da9690b
to
75f968a
Compare
I renamed New commit message:
|
@@ -242,7 +243,7 @@ BIND_GLOBAL("ErrorInner", | |||
res := fail; | |||
fi; | |||
ErrorLevel := ErrorLevel-1; | |||
ErrorLVars := errorLVars; | |||
ErrorLVars := ErrorLVarsOld; |
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.
With this change, nested errors won't work -- i.e. nested break loops.
All you need is the correct ErrorLVars
in your OnBreak
handler, right? So you simply leave errorLVars
as it is, but insert ErrorLVars := errorLVars;
right before the call to OnBreak
. That should never cause harms, but would remove the need for your OnBreak
handler to do anything.
I.e. this PR would essentially insert a single line.
Does that work?
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.
Since the nested break loops don't work like this this can't be merged.
I think the problem with setting ErrorLVars := errorLVars;
right before calling OnBreak()
is that currently, when entering OnBreak
, ErrorLVars
is set to context
. Where
uses ErrorLVars
to access context
to print the traceback. (if only OnBreak
could take context
as an argument..)
Or did I misunderstand something there?
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.
OK, I just re-read the whole of ErrorInner
(as I should have done before my comments sigh), and yes, you are right.
But what should work is adding a new global ErrorLVarsOld
as you did, but retaining errorLVars
; then set ErrorLVarsOld
only just before calling OnBreak
. That's not very nice, because we are essentially passing an argument through a global variable, but it'd work.
But yeah, at this point, we might as well introduce AlwaysShowTracebackOnError
as discussed in issue #2547.
And refactor this code later on again ;-).
I will close this in favor of a global variable |
This is a bit dirty. Setting BreakOnError := false suppressesboth the break loop and the traceback. So to make the traceback
available under jupyter ErrorInner checks whether a JupyterKernel
is currently running.
See new commit message below.