Skip to content

Commit e19636f

Browse files
fingolfincodex
andauthored
Error handling: split stack frames over two lines; adjust more manual examples (#6263)
Render visible stack frames with numbered prefixes on one line and an aligned location line below, and give compiled GAP frames a stacktrace-specific format. AI-assisted with Codex for implementation, tests, and documentation. Co-authored-by: Codex <codex@openai.com>
1 parent 97a9d24 commit e19636f

48 files changed

Lines changed: 910 additions & 475 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/ref/debug.xml

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -915,41 +915,33 @@ to terminate the calculation, or enter <B>Return</B><C>;</C> to continue it.
915915
gap> dive:= function(depth) if depth>1 then dive(depth-1); fi; return; end;
916916
function( depth ) ... end
917917
gap> dive(100);
918-
gap> OnBreak:= function() Where(1); end; # shorter traceback
919-
function( ) ... end
918+
gap> OnBreak:= function() Where(2); end;; # shorter traceback
920919
gap> dive(6000);
921-
recursion depth trap (5000)
922-
at
923-
dive( depth - 1 );
924-
called from
925-
dive( depth - 1 ); called from
926-
...
927-
Entering break read-eval-print loop ...
928-
you can 'quit;' to quit to outer loop, or
929-
you may 'return;' to continue
920+
Error, recursion depth trap (5000)
921+
*[1] dive( depth - 1 );
922+
@ *stdin*:1
923+
[2] dive( depth - 1 );
924+
@ *stdin*:1
925+
... at *stdin*:4
926+
you may 'return;'
930927
brk> return;
931928
gap> dive(11000);
932-
recursion depth trap (5000)
933-
at
934-
dive( depth - 1 );
935-
called from
936-
dive( depth - 1 ); called from
937-
...
938-
Entering break read-eval-print loop ...
939-
you can 'quit;' to quit to outer loop, or
940-
you may 'return;' to continue
929+
Error, recursion depth trap (5000)
930+
*[1] dive( depth - 1 );
931+
@ *stdin*:1
932+
[2] dive( depth - 1 );
933+
@ *stdin*:1
934+
... at *stdin*:5
935+
you may 'return;'
941936
brk> return;
942-
recursion depth trap (10000)
943-
at
944-
dive( depth - 1 );
945-
called from
946-
dive( depth - 1 ); called from
947-
...
948-
Entering break read-eval-print loop ...
949-
you can 'quit;' to quit to outer loop, or
950-
you may 'return;' to continue
951-
brk> return;
952-
gap>
937+
Error, recursion depth trap (10000)
938+
*[1] dive( depth - 1 );
939+
@ *stdin*:1
940+
[2] dive( depth - 1 );
941+
@ *stdin*:1
942+
... at *stdin*:5
943+
you may 'return;'
944+
brk> return;gap>
953945
]]></Log>
954946
<P/>
955947

@@ -979,39 +971,29 @@ gap> dive := function(depth)
979971
> fi;
980972
> end;;
981973
gap> SetRecursionTrapInterval(1000);
974+
gap> OnBreak:= function() Where(2); end;; # shorter traceback
982975
gap> dive(100);
983976
Depth 100
984977
gap> dive(2500);
985-
recursion depth trap (1000)
986-
at
987-
dive( depth - 1 );
988-
called from
989-
dive( depth - 1 ); called from
990-
...
991-
Entering break read-eval-print loop ...
992-
you can 'quit;' to quit to outer loop, or
993-
you may 'return;' to continue
978+
Error, recursion depth trap (1000)
979+
*[1] dive( depth - 1 );
980+
@ *stdin*:4
981+
[2] dive( depth - 1 );
982+
@ *stdin*:4
983+
... at *stdin*:12
984+
you may 'return;'
994985
brk> return;
995-
recursion depth trap (2000)
996-
at
997-
dive( depth - 1 );
998-
called from
999-
dive( depth - 1 ); called from
1000-
...
1001-
Entering break read-eval-print loop ...
1002-
you can 'quit;' to quit to outer loop, or
1003-
you may 'return;' to continue
986+
Error, recursion depth trap (2000)
987+
*[1] dive( depth - 1 );
988+
@ *stdin*:4
989+
[2] dive( depth - 1 );
990+
@ *stdin*:4
991+
... at *stdin*:12
992+
you may 'return;'
1004993
brk> GetRecursionDepth();
1005994
0
1006995
brk> return;
1007-
gap> SetRecursionTrapInterval(-1);
1008-
Error, SetRecursionTrapInterval: <interval> must be a small integer greater than 5 (n\
1009-
ot the integer -1)
1010-
not in any function
1011-
Entering break read-eval-print loop ...
1012-
you can 'quit;' to quit to outer loop, or
1013-
you can replace <interval> via 'return <interval>;' to continue
1014-
brk> return 0;
996+
gap> SetRecursionTrapInterval(2^50);
1015997
gap> dive(20000);
1016998
Depth 20000
1017999
gap> dive(2000000);

doc/ref/grpperm.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,7 @@ gap> h:=Group(permutationlist);
652652
<permutation group with 5 generators>
653653
gap> StabChainOptions(h).random:=1;;
654654
gap> Size(h);
655-
exceeded the permitted memory (`-o' command line option) at
656-
mlimit := 1; called from
657-
SCRMakeStabStrong( S.stabilizer, [ g ], param, orbits, where, basesize,
658-
base, correct, missing, false ); called from
659-
SCRMakeStabStrong( S.stabilizer, [ g ], param, orbits, where, basesize,
655+
exceeded the permitted memory (`-o' command line option)
660656
...
661657
]]></Log>
662658
<P/>

doc/ref/language.xml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,24 +1556,19 @@ If the expression <A>expr</A> is a function call then this function must
15561556
return a value. If the function does not return a value an error is
15571557
signalled and you enter a break loop (see <Ref Sect="Break Loops"/>).
15581558
As usual you can leave the break loop with <C>quit;</C>.
1559-
If you enter <C>return <A>return-expr</A>;</C> the value of the expression
1560-
<A>return-expr</A> is assigned to the variable,
1561-
and execution continues after the assignment.
15621559
<P/>
15631560
<Log><![CDATA[
15641561
gap> f1:= function( x ) Print( "value: ", x, "\n" ); end;;
15651562
gap> f2:= function( x ) return f1( x ); end;;
15661563
gap> f2( 4 );
15671564
value: 4
1568-
Function Calls: <func> must return a value at
1569-
return f1( x );
1570-
called from
1571-
<function>( <arguments> ) called from read-eval-loop
1572-
Entering break read-eval-print loop ...
1573-
you can 'quit;' to quit to outer loop, or
1574-
you can supply one by 'return <value>;' to continue
1575-
brk> return "hello";
1576-
"hello"
1565+
Error, Function Calls: <func> must return a value
1566+
*[1] f1( x )
1567+
@ *stdin*:2
1568+
<function "f2">( <arguments> )
1569+
called from read-eval loop at *stdin*:3
1570+
type 'quit;' to quit to outer loop
1571+
brk>
15771572
]]></Log>
15781573
<P/>
15791574
In the above example, the function <C>f2</C> calls <C>f1</C> with argument

doc/ref/methsel.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,15 @@ objecty, a "No Method Found" error will be returned.
125125
<Log><![CDATA[
126126
gap> XCons(IsFullTransformationMonoid,4);
127127
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
128-
Error, no 1st choice method found for `XCons' on 2 arguments called from
129-
<function "HANDLE_METHOD_NOT_FOUND">( <arguments> )
130-
called from read-eval loop at line 8 of *stdin*
131-
you can 'quit;' to quit to outer loop, or
132-
you can 'return;' to continue
128+
Error, no 1st choice method found for `XCons' on 2 arguments
129+
called from read-eval loop at *stdin*:8
130+
type 'quit;' to quit to outer loop
133131
brk> quit;
134132
gap> XCons(IsNilpotentGroup,4);
135133
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
136-
Error, no 1st choice method found for `XCons' on 2 arguments called from
137-
<function "HANDLE_METHOD_NOT_FOUND">( <arguments> )
138-
called from read-eval loop at line 9 of *stdin*
139-
you can 'quit;' to quit to outer loop, or
140-
you can 'return;' to continue
134+
Error, no 1st choice method found for `XCons' on 2 arguments
135+
called from read-eval loop at *stdin*:8
136+
type 'quit;' to quit to outer loop
141137
brk>
142138
]]></Log>
143139

@@ -435,4 +431,3 @@ the mathematical term <Q>centre</Q>.
435431
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
436432
<!-- %% -->
437433
<!-- %E -->
438-

doc/ref/mloop.xml

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -476,24 +476,20 @@ indicate that you are in a break loop.
476476
<P/>
477477
<Log><![CDATA[
478478
gap> 1/0;
479-
Rational operations: <divisor> must not be zero
480-
not in any function
481-
Entering break read-eval-print loop ...
482-
you can 'quit;' to quit to outer loop, or
483-
you can replace <divisor> via 'return <divisor>;' to continue
479+
Error, Rational operations: <divisor> must not be zero
480+
not in any function at *stdin*:2
481+
type 'quit;' to quit to outer loop
484482
]]></Log>
485483
<P/>
486484
If errors occur within a break loop &GAP; enters another break loop at a
487485
<E>deeper level</E>. This is indicated by a number appended to <C>brk</C>:
488486
<P/>
489487
<Log><![CDATA[
490488
brk> 1/0;
491-
Rational operations: <divisor> must not be zero
492-
not in any function
493-
Entering break read-eval-print loop ...
494-
you can 'quit;' to quit to outer loop, or
495-
you can replace <divisor> via 'return <divisor>;' to continue
496-
brk_02>
489+
Error, Rational operations: <divisor> must not be zero
490+
not in any function at *stdin*:2
491+
type 'quit;' to quit to outer loop
492+
brk_2>
497493
]]></Log>
498494
<P/>
499495
There are two ways to leave a break loop,
@@ -511,7 +507,7 @@ Note that &GAP; code between <C>quit;</C> and the end of the input line
511507
is ignored.
512508
<P/>
513509
<Log><![CDATA[
514-
brk_02> quit;
510+
brk_2> quit;
515511
brk>
516512
]]></Log>
517513
<P/>
@@ -750,25 +746,30 @@ same as <Ref Func="Where"/> while also showing the arguments and local
750746
variables of each function.
751747
<P/>
752748
<Log><![CDATA[
753-
gap> StabChain(SymmetricGroup(100)); # After this we typed ^C
754-
user interrupt at
755-
bpt := S.orbit[1];
756-
called from
757-
SiftedPermutation( S, (g * rep) ^ -1 ) called from
758-
StabChainStrong( S.stabilizer, [ sch ], options ); called from
759-
StabChainStrong( S.stabilizer, [ sch ], options ); called from
760-
StabChainStrong( S, GeneratorsOfGroup( G ), options ); called from
761-
StabChainOp( G, rec(
762-
) ) called from
763-
...
764-
Entering break read-eval-print loop ...
765-
you can 'quit;' to quit to outer loop, or
766-
you can 'return;' to continue
749+
gap> StabChain(SymmetricGroup(1000)); # After this we typed ^C
750+
Error, user interrupt
751+
*[1] genlabels := Filtered( genlabels, function ( x )
752+
return pnt ^ sgs[x] = pnt;
753+
end );
754+
@ GAPROOT/lib/stbc.gi:426
755+
[2] StabChainBaseStrongGenerators( dom{[ 1 .. Length( dom ) - 1 ]}, sgs, () )
756+
@ GAPROOT/lib/gpprmsya.gi:2006
757+
[3] StabChainOp( G, rec(
758+
) )
759+
@ GAPROOT/lib/stbc.gi:28
760+
[4] StabChainImmutable( arg[1] )
761+
@ GAPROOT/lib/stbc.gi:18
762+
<function "StabChain">( <arguments> )
763+
called from read-eval loop at *stdin*:2
764+
you can 'return;'
767765
brk> Where(2);
768-
called from
769-
SiftedPermutation( S, (g * rep) ^ -1 ) called from
770-
StabChainStrong( S.stabilizer, [ sch ], options ); called from
771-
...
766+
*[1] genlabels := Filtered( genlabels, function ( x )
767+
return pnt ^ sgs[x] = pnt;
768+
end );
769+
@ GAPROOT/lib/stbc.gi:426
770+
[2] StabChainBaseStrongGenerators( dom{[ 1 .. Length( dom ) - 1 ]}, sgs, () )
771+
@ GAPROOT/lib/gpprmsya.gi:2006
772+
... at *errin*:1
772773
]]></Log>
773774
<P/>
774775
Note that the variables displayed even in the first line of the
@@ -836,10 +837,14 @@ Error, !
836837
you can 'quit;' to quit to outer loop, or
837838
you can 'return;' to continue
838839
brk> Where();
839-
*[1] Error( "!\n" ); at *stdin*:3 called from
840-
[2] test( n + 1 ); at *stdin*:3 called from
841-
[3] test( n + 1 ); at *stdin*:3 called from
842-
[4] test( n + 1 ); at *stdin*:3 called from
840+
*[1] Error( "!\n" );
841+
@ *stdin*:4
842+
[2] test( n + 1 );
843+
@ *stdin*:4
844+
[3] test( n + 1 );
845+
@ *stdin*:4
846+
[4] test( n + 1 );
847+
@ *stdin*:4
843848
<function "test">( <arguments> )
844849
called from read-eval loop at *errin*:1
845850
brk> n;
@@ -848,20 +853,28 @@ brk> DownEnv();
848853
brk> n;
849854
3
850855
brk> Where();
851-
[1] Error( "!\n" ); at *stdin*:3 called from
852-
*[2] test( n + 1 ); at *stdin*:3 called from
853-
[3] test( n + 1 ); at *stdin*:3 called from
854-
[4] test( n + 1 ); at *stdin*:3 called from
856+
[1] Error( "!\n" );
857+
@ *stdin*:4
858+
*[2] test( n + 1 );
859+
@ *stdin*:4
860+
[3] test( n + 1 );
861+
@ *stdin*:4
862+
[4] test( n + 1 );
863+
@ *stdin*:4
855864
<function "test">( <arguments> )
856865
called from read-eval loop at *errin*:5
857866
brk> DownEnv( 2 );
858867
brk> n;
859868
1
860869
brk> Where();
861-
[1] Error( "!\n" ); at *stdin*:3 called from
862-
[2] test( n + 1 ); at *stdin*:3 called from
863-
[3] test( n + 1 ); at *stdin*:3 called from
864-
*[4] test( n + 1 ); at *stdin*:3 called from
870+
[1] Error( "!\n" );
871+
@ *stdin*:4
872+
[2] test( n + 1 );
873+
@ *stdin*:4
874+
[3] test( n + 1 );
875+
@ *stdin*:4
876+
*[4] test( n + 1 );
877+
@ *stdin*:4
865878
<function "test">( <arguments> )
866879
called from read-eval loop at *errin*:8
867880
brk> DownEnv( -2 );
@@ -894,10 +907,13 @@ gap> fun := function() local x; x := 3; bar(); end;
894907
function( ) ... end
895908
gap> fun();
896909
Error, !!
897-
called from
898-
bar( ); called from
899-
<function>( <arguments> ) called from read-eval-loop
900-
Entering break read-eval-print loop ...
910+
Stack trace:
911+
*[1] Error( "!!\n" );
912+
@ *stdin*:4
913+
[2] bar( );
914+
@ *stdin*:7
915+
<function "fun">( <arguments> )
916+
called from read-eval loop at *stdin*:8
901917
you can 'quit;' to quit to outer loop, or
902918
you can 'return;' to continue
903919
brk> x;

doc/tut/group.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,11 +927,12 @@ gap> Size( Image( hom, DerivedSubgroup(s4) ) );
927927
<P/>
928928
<Log><![CDATA[
929929
gap> PreImage( hom, (1,2,3) );
930-
Error, <map> must be an inj. and surj. mapping called from
930+
Error, <map> must be an injective and surjective mapping
931+
*[1] ErrorNoReturn( "<map> must be an injective and surjective ", "mapping" );
932+
@ GAPROOT/lib/mapping.gi:262
931933
<function "PreImage">( <arguments> )
932-
called from read-eval loop at line 4 of *stdin*
933-
you can 'quit;' to quit to outer loop, or
934-
you can 'return;' to continue
934+
called from read-eval loop at *stdin*:7
935+
type 'quit;' to quit to outer loop
935936
brk> quit;
936937
]]></Log>
937938
<P/>
@@ -1258,4 +1259,3 @@ Chapter&nbsp;<Ref Chap="Group Homomorphisms" BookName="ref"/>.
12581259
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
12591260
<!-- %% -->
12601261
<!-- %E -->
1261-

doc/tut/introduc.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ We will no longer mention the <B>Return</B> key from now on.
253253
<Index>break loops</Index>
254254
Sometimes a syntax error will cause &GAP; to enter a <E>break loop</E>. This
255255
is indicated by the special prompt <C>brk></C>. If another syntax error occurs
256-
while &GAP; is in a break loop, the prompt will change to <C>brk_02></C>,
257-
<C>brk_03></C> and so on. You can leave the current break loop and exit to the
256+
while &GAP; is in a break loop, the prompt will change to <C>brk_2></C>,
257+
<C>brk_3></C> and so on. You can leave the current break loop and exit to the
258258
next outer one by either typing <C>quit;</C> or by hitting <B>Ctrl-D</B>.
259259
Eventually &GAP; will return to its normal state and show its normal
260260
prompt <C>gap></C> again.

0 commit comments

Comments
 (0)