Skip to content

Commit

Permalink
New command line option --alwaystrace
Browse files Browse the repository at this point in the history
The option --alwaystrace sets a new global variable
AlwaysPrintTracebackOnError. If set to true `OnBreak()` is always
called before exiting `ErrorInner`.
  • Loading branch information
ssiccha committed Jul 6, 2018
1 parent b259697 commit 3251a8f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/error.g
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ BIND_GLOBAL("ErrorInner",
LEAVE_ALL_NAMESPACES();
JUMP_TO_CATCH(1);
fi;

# Local functions that print the user feedback.
printEarlyMessage := function(stream, earlyMessage)
PrintTo(stream, "Error, ");
Expand Down Expand Up @@ -222,12 +222,21 @@ BIND_GLOBAL("ErrorInner",
if QUITTING or not BreakOnError then
# If we skip the break loop, the standard behaviour is to print only
# the earlyMessage. If SilentNonInteractiveErrors is true we do not
# print any messages.
# This is used by HPC-GAP to e.g. suppress error messages in worker
# print any messages. If AlwaysPrintTracebackOnError is true we also
# call OnBreak(), which by default prints the traceback.
# SilentNonInteractiveErrors superseeds AlwaysPrintTracebackOnError.
# It is used by HPC-GAP to e.g. suppress error messages in worker
# threads.
if not SilentNonInteractiveErrors then
printEarlyMessage("*errout*", earlyMessage);
PrintTo("*errout*", "\n");
if AlwaysPrintTracebackOnError then
printEarlyTraceback("*errout*", context, printThisStatement);
if IsBound(OnBreak) and IsFunction(OnBreak) then
OnBreak();
fi;
else
PrintTo("*errout*", "\n");
fi;
fi;
if IsHPCGAP then
# In HPC-GAP we want to access error messages encountered in
Expand All @@ -236,6 +245,17 @@ BIND_GLOBAL("ErrorInner",
LastErrorMessage := "";
lastErrorStream := OutputTextString(LastErrorMessage, true);
printEarlyMessage(lastErrorStream, earlyMessage);
if AlwaysPrintTracebackOnError then
printEarlyTraceback(lastErrorStream, context, printThisStatement);
# FIXME: Also make HPCGAP work with OnBreak().
# If AlwaysPrintTracebackOnError is true, the output of
# OnBreak() should also be put into LastErrorMessage.
# To do this there needs to be a way to put its output
# into lastErrorStream.
# OnBreak() is documented to not take any arguments.
# One could work around that if there were e.g. a GAP error
# stream which all error functions print to.
fi;
CloseStream(lastErrorStream);
MakeImmutable(LastErrorMessage);
fi;
Expand All @@ -249,6 +269,14 @@ BIND_GLOBAL("ErrorInner",
printEarlyTraceback("*errout*", context, printThisStatement);

if SHOULD_QUIT_ON_BREAK() then
# Again, the default is to not print the rest of the traceback.
# If AlwaysPrintTracebackOnError is true we do so anyways.
if
AlwaysPrintTracebackOnError
and IsBound(OnBreak) and IsFunction(OnBreak)
then
OnBreak();
fi;
FORCE_QUIT_GAP(1);
fi;

Expand Down
7 changes: 7 additions & 0 deletions lib/init.g
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ fi;
##
## - Unbind `DEBUG_LOADING', since later the `-D' option can be checked.
## - Set or disable break loop according to the `-T' option.
## - Set whether traceback may be suppressed (e.g. by `-T') according to the
## `--alwaystrace' option.
##
CallAndInstallPostRestore( function()
if DEBUG_LOADING then
Expand All @@ -248,10 +250,15 @@ CallAndInstallPostRestore( function()

if IsHPCGAP then
BindThreadLocal( "BreakOnError", not GAPInfo.CommandLineOptions.T );
BindThreadLocal(
"AlwaysPrintTracebackOnError",
GAPInfo.CommandLineOptions.alwaystrace
);
BindThreadLocal( "SilentNonInteractiveErrors", false );
BindThreadLocal( "LastErrorMessage", "" );
else
ASS_GVAR( "BreakOnError", not GAPInfo.CommandLineOptions.T );
ASS_GVAR( "AlwaysPrintTracebackOnError", GAPInfo.CommandLineOptions.alwaystrace );
ASS_GVAR( "SilentNonInteractiveErrors", false );
fi;
end);
Expand Down
1 change: 1 addition & 0 deletions lib/system.g
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ BIND_GLOBAL( "GAPInfo", rec(
rec( short:= "N", default := false, help := ["do not use hidden implications"] ),
rec( short:= "O", default := false, help := ["disable/enable loading of obsolete files"] ),
rec( short:= "T", long := "nobreakloop", default := false, help := ["disable/enable break loop and error traceback"] ),
rec( long := "alwaystrace", default := false, help := ["always print error traceback (overrides behaviour of -T)"] ),
rec( long := "quitonbreak", default := false, help := ["quit GAP with non-zero return value instead of entering break loop"]),
,
rec( short:= "L", default := "", arg := "<file>", help := [ "restore a saved workspace"] ),
Expand Down

0 comments on commit 3251a8f

Please sign in to comment.