Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/ref/mloop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,11 @@ is an example in the ⪆ code where the idea is actually used.
<Index Subkey="GAP3 name for Where">Backtrace</Index>
<Index>Stack trace</Index>
shows the last <A>nr</A> commands on the execution stack during whose execution
the error occurred. If not given, <A>nr</A> defaults to 5. (Assume, for the
the error occurred. If not given, <A>nr</A> defaults to the value of the
<C>WhereDepth</C> user preference (initially 5).
If <A>nr</A> or the <C>WhereDepth</C> preference is not a non-negative integer,
it is treated as 5.
(Assume, for the
following example, that after the last example <Ref Func="OnBreak"/>
has been set back to its default value.). <Ref Func="WhereWithVars"/> acts the
same as <Ref Func="Where"/> while also showing the arguments and local
Expand Down
7 changes: 5 additions & 2 deletions lib/error.g
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ end);

BIND_GLOBAL("WHERE_INTERNAL", function(depth, showlocals)
local activecontext;
if not IsInt(depth) or depth < 0 then
depth := 5;
fi;
if ErrorLVars = fail or ErrorLVars = GetBottomLVars() then
PrintTo(ERROR_OUTPUT, "not in any function ");
else
Expand All @@ -181,7 +184,7 @@ end);
BIND_GLOBAL("WhereWithVars", function(arg)
local depth;
if LEN_LIST(arg) = 0 then
depth := 5;
depth := UserPreference("WhereDepth");
else
depth := arg[1];
fi;
Expand All @@ -192,7 +195,7 @@ end);
BIND_GLOBAL("Where", function(arg)
local depth;
if LEN_LIST(arg) = 0 then
depth := 5;
depth := UserPreference("WhereDepth");
else
depth := arg[1];
fi;
Expand Down
11 changes: 11 additions & 0 deletions lib/init.g
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,17 @@ DeclareUserPreference( rec(
default:= 3,
check:= val -> IsInt( val ) and 0 <= val,
) );
DeclareUserPreference( rec(
name:= "WhereDepth",
description:= [
"The number of stack frames shown by <C>Where</C> and <C>WhereWithVars</C> \
when called without an explicit depth argument, e.g. in the default <C>OnBreak</C> \
handler. Increase this value if the default of 5 is not enough to locate the \
source of an error."
],
default:= 5,
check:= val -> IsInt( val ) and 0 <= val,
) );
DeclareUserPreference( rec(
name:= "ReproducibleBehaviour",
description:= [
Expand Down
15 changes: 15 additions & 0 deletions tst/testinstall/error.tst
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ gap> if false then Stabilizer; fi;
Syntax error: found an expression when a statement was expected in stream:1
if false then Stabilizer; fi;
^

#
# WhereDepth user preference
#
gap> UserPreference("WhereDepth");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail if the user changed the preference

Copy link
Copy Markdown
Member Author

@limakzi limakzi Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tests defaults.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't test default, it queries the current setting, which may or may not be the default value. On my computer it most likely will not be the default value 5 but rather something like 30

5
gap> SetUserPreference("WhereDepth", 10);
gap> UserPreference("WhereDepth");
10
gap> SetUserPreference("WhereDepth", 0);
gap> UserPreference("WhereDepth");
0
gap> SetUserPreference("WhereDepth", 5);
gap> UserPreference("WhereDepth");
Comment on lines +43 to +50
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this really just testing the UserPreference system, not WhereDepth? that doesn't strike me as super useful.

Instead, the place to test this ought to be in tst/testspecial/backtrace.g or tst/testspecial/backtrace2.g or so (actually... probably in tst/testspecial/stack-trace-depth.g but that only gets added in PR #6263 -- so now I am thinking about adding it right away in a PR of its own, with the "old" Where, so that (a) you can use it here, (b) one sees how the output compares from old to new in my PR.

And that also reminds me of another issue: all those tests producing backtraces will break if the user running the test suite has a custom WhereDepth set. This will affect me as I will immediately set WhereDepth to 30 or so .

To solve this, tst/testspecial/run_gap.sh needs to be edited to do SetUserPreference("WhereDepth", 5); (it already changes UseColorsInTerminal so it should be easy to do this)

5
Loading