Skip to content

Commit 3251a8f

Browse files
committed
New command line option --alwaystrace
The option --alwaystrace sets a new global variable AlwaysPrintTracebackOnError. If set to true `OnBreak()` is always called before exiting `ErrorInner`.
1 parent b259697 commit 3251a8f

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

lib/error.g

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ BIND_GLOBAL("ErrorInner",
185185
LEAVE_ALL_NAMESPACES();
186186
JUMP_TO_CATCH(1);
187187
fi;
188-
188+
189189
# Local functions that print the user feedback.
190190
printEarlyMessage := function(stream, earlyMessage)
191191
PrintTo(stream, "Error, ");
@@ -222,12 +222,21 @@ BIND_GLOBAL("ErrorInner",
222222
if QUITTING or not BreakOnError then
223223
# If we skip the break loop, the standard behaviour is to print only
224224
# the earlyMessage. If SilentNonInteractiveErrors is true we do not
225-
# print any messages.
226-
# This is used by HPC-GAP to e.g. suppress error messages in worker
225+
# print any messages. If AlwaysPrintTracebackOnError is true we also
226+
# call OnBreak(), which by default prints the traceback.
227+
# SilentNonInteractiveErrors superseeds AlwaysPrintTracebackOnError.
228+
# It is used by HPC-GAP to e.g. suppress error messages in worker
227229
# threads.
228230
if not SilentNonInteractiveErrors then
229231
printEarlyMessage("*errout*", earlyMessage);
230-
PrintTo("*errout*", "\n");
232+
if AlwaysPrintTracebackOnError then
233+
printEarlyTraceback("*errout*", context, printThisStatement);
234+
if IsBound(OnBreak) and IsFunction(OnBreak) then
235+
OnBreak();
236+
fi;
237+
else
238+
PrintTo("*errout*", "\n");
239+
fi;
231240
fi;
232241
if IsHPCGAP then
233242
# In HPC-GAP we want to access error messages encountered in
@@ -236,6 +245,17 @@ BIND_GLOBAL("ErrorInner",
236245
LastErrorMessage := "";
237246
lastErrorStream := OutputTextString(LastErrorMessage, true);
238247
printEarlyMessage(lastErrorStream, earlyMessage);
248+
if AlwaysPrintTracebackOnError then
249+
printEarlyTraceback(lastErrorStream, context, printThisStatement);
250+
# FIXME: Also make HPCGAP work with OnBreak().
251+
# If AlwaysPrintTracebackOnError is true, the output of
252+
# OnBreak() should also be put into LastErrorMessage.
253+
# To do this there needs to be a way to put its output
254+
# into lastErrorStream.
255+
# OnBreak() is documented to not take any arguments.
256+
# One could work around that if there were e.g. a GAP error
257+
# stream which all error functions print to.
258+
fi;
239259
CloseStream(lastErrorStream);
240260
MakeImmutable(LastErrorMessage);
241261
fi;
@@ -249,6 +269,14 @@ BIND_GLOBAL("ErrorInner",
249269
printEarlyTraceback("*errout*", context, printThisStatement);
250270

251271
if SHOULD_QUIT_ON_BREAK() then
272+
# Again, the default is to not print the rest of the traceback.
273+
# If AlwaysPrintTracebackOnError is true we do so anyways.
274+
if
275+
AlwaysPrintTracebackOnError
276+
and IsBound(OnBreak) and IsFunction(OnBreak)
277+
then
278+
OnBreak();
279+
fi;
252280
FORCE_QUIT_GAP(1);
253281
fi;
254282

lib/init.g

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ fi;
236236
##
237237
## - Unbind `DEBUG_LOADING', since later the `-D' option can be checked.
238238
## - Set or disable break loop according to the `-T' option.
239+
## - Set whether traceback may be suppressed (e.g. by `-T') according to the
240+
## `--alwaystrace' option.
239241
##
240242
CallAndInstallPostRestore( function()
241243
if DEBUG_LOADING then
@@ -248,10 +250,15 @@ CallAndInstallPostRestore( function()
248250

249251
if IsHPCGAP then
250252
BindThreadLocal( "BreakOnError", not GAPInfo.CommandLineOptions.T );
253+
BindThreadLocal(
254+
"AlwaysPrintTracebackOnError",
255+
GAPInfo.CommandLineOptions.alwaystrace
256+
);
251257
BindThreadLocal( "SilentNonInteractiveErrors", false );
252258
BindThreadLocal( "LastErrorMessage", "" );
253259
else
254260
ASS_GVAR( "BreakOnError", not GAPInfo.CommandLineOptions.T );
261+
ASS_GVAR( "AlwaysPrintTracebackOnError", GAPInfo.CommandLineOptions.alwaystrace );
255262
ASS_GVAR( "SilentNonInteractiveErrors", false );
256263
fi;
257264
end);

lib/system.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ BIND_GLOBAL( "GAPInfo", rec(
9595
rec( short:= "N", default := false, help := ["do not use hidden implications"] ),
9696
rec( short:= "O", default := false, help := ["disable/enable loading of obsolete files"] ),
9797
rec( short:= "T", long := "nobreakloop", default := false, help := ["disable/enable break loop and error traceback"] ),
98+
rec( long := "alwaystrace", default := false, help := ["always print error traceback (overrides behaviour of -T)"] ),
9899
rec( long := "quitonbreak", default := false, help := ["quit GAP with non-zero return value instead of entering break loop"]),
99100
,
100101
rec( short:= "L", default := "", arg := "<file>", help := [ "restore a saved workspace"] ),

0 commit comments

Comments
 (0)