Skip to content

Add WhereDepth user preference to control depth of initial stack trace in break loops#6261

Open
limakzi wants to merge 2 commits intogap-system:masterfrom
limakzi:6210-add-where-clause
Open

Add WhereDepth user preference to control depth of initial stack trace in break loops#6261
limakzi wants to merge 2 commits intogap-system:masterfrom
limakzi:6210-add-where-clause

Conversation

@limakzi
Copy link
Member

@limakzi limakzi commented Mar 10, 2026

Adds a WhereDepth user preference that controls the default number of stack frames shown by Where and WhereWithVars when called without an explicit depth argument (i.e. in the default OnBreak handler).

Previously this was hardcoded to 5.
The default remains 5, so existing behaviour is unchanged.

Fixes #6210

@limakzi limakzi marked this pull request as ready for review March 10, 2026 11:07
Copilot AI review requested due to automatic review settings March 10, 2026 11:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new core GAP user preference (WhereDepth) to control the default stack depth used by Where / WhereWithVars when called with no explicit argument (notably via the default OnBreak handler), keeping the default behavior at 5.

Changes:

  • Declare new WhereDepth user preference (default 5, non-negative integer).
  • Use UserPreference("WhereDepth") as the default depth in Where and WhereWithVars.
  • Add an installation test that verifies the preference exists and can be changed.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/init.g Declares the new WhereDepth user preference with default/check logic.
lib/error.g Switches Where / WhereWithVars default depth from constant 5 to UserPreference("WhereDepth").
tst/testinstall/error.tst Adds a basic regression test for reading/setting WhereDepth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: error handling release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: library labels Mar 11, 2026
@fingolfin fingolfin changed the title feat: Add WhereDepth user preference for stack depth Add WhereDepth user preference to control depth of initial stack trace in break loops Mar 11, 2026
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Actually, this also needs to adjust the Where documentation, which currently states

If not given, nr defaults to 5.

@limakzi limakzi force-pushed the 6210-add-where-clause branch from 66a05f7 to bc114ff Compare March 12, 2026 21:55
@limakzi limakzi requested a review from fingolfin March 12, 2026 21:56
#
# WhereDepth user preference
#
gap> UserPreference("WhereDepth");
Copy link
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
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
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

Comment on lines +43 to +50
gap> SetUserPreference("WhereDepth", 10);
gap> UserPreference("WhereDepth");
10
gap> SetUserPreference("WhereDepth", 0);
gap> UserPreference("WhereDepth");
0
gap> SetUserPreference("WhereDepth", 5);
gap> UserPreference("WhereDepth");
Copy link
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)

Co-authored-by: Max Horn <max@quendi.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: error handling topic: library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a user preference for changing the default limit for Where from 5 to something else

3 participants