Skip to content

Conversation

@9999years
Copy link
Contributor

@9999years 9999years commented Feb 3, 2024

Motivation

With --debugger --debugger-on-trace, builtins.trace calls will start the interactive debugger, exposing stack trace information.

Context

Closes #1610.

I recently complained that my Nix project was emitting warnings with no clear provenance:

$ nix develop
trace: warning: `pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`
$ rg pythonForBuild | wc -l
0

With this patch, it's easy to print a backtrace:

nix develop --debugger --debugger-on-trace
trace: warning: `pythonForBuild` (from `python*`) has been renamed to `pythonOnBuildForHost`
Welcome to Nix 2.21.0pre20240131_dirty. Type :? for help.

nix-repl> :bt

0: while evaluating the attribute 'python311.pythonForBuild.pkgs'
/nix/store/hg65h51xnp74ikahns9hyf3py5mlbbqq-source/overrides/default.nix:132:27

   131|
   132|       bootstrappingBase = pkgs.${self.python.pythonAttr}.pythonForBuild.pkgs;
      |                           ^
   133|     in

Then, we can look at the source path to see that it's a checkout of poetry2nix:

$ head /nix/store/hg65h51xnp74ikahns9hyf3py5mlbbqq-source/README.md
[![](https://github.com/nix-community/poetry2nix/workflows/CI/badge.svg)](https://github.com/nix-community/poetry2nix/actions?query=branch%3Amaster+workflow%3ACI)
[![Chat on Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#poetry2nix:blad.is)

# poetry2nix

Nice!

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@9999years
Copy link
Contributor Author

9999years commented Feb 3, 2024

Added a changelog entry.

Note: If this PR is merged, #9916 should be merged as well or the behavior of :quit becomes confusing.

"The maximum function call depth to allow before erroring."};

Setting<bool> builtinsTraceDebugger{this, false, "builtins-trace-debugger",
"Whether to enter the debugger on `builtins.trace` calls."};
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add links to documentation of debugger and builtins.trace. People who start reading from the command reference otherwise won't know what either means or where to find that information.

Copy link
Contributor

Choose a reason for hiding this comment

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

splitting it like this could also be a source of confusion since --debugger is not implied. perhaps it'd be better to implicitly enable the debugger when this setting is set and change the name to something that signifies such, eg --debugger-on-trace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

image image

@thufschmitt thufschmitt merged commit 774e7ca into NixOS:master Feb 21, 2024
@9999years 9999years deleted the debugger-on-trace branch March 25, 2024 19:38
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
Enter debugger on `builtins.trace` with an option

(cherry picked from commit 774e7ca)
Change-Id: If01e2110b3a128e639b05143227e365227d149f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Feature request: Print backtrace in trace output

4 participants