Skip to content

Changes to make Nix output more informative errors - #612

Closed
Mathnerd314 wants to merge 3 commits into
NixOS:masterfrom
Mathnerd314:noisy-nix
Closed

Mathnerd314 wants to merge 3 commits into
NixOS:masterfrom
Mathnerd314:noisy-nix

Conversation

@Mathnerd314

Copy link
Copy Markdown
Contributor
  • Output several more locations during --show-trace
  • Option -C / --color for use with less -r
  • nix-instantiate respects '-k' by continuing evaluation after errors (only with derivations)

Comment thread src/libexpr/get-drvs.cc Outdated

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.

Indentation a bit odd here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess I was a bit too focused on minimizing the diff. Fixed.

* Option -C / --color for use with less -r
* nix-instantiate respects '-k' by continuing evaluation after errors (only with derivations)
@Mathnerd314

Copy link
Copy Markdown
Contributor Author

@edolstra Is there any possibility of this being merged?

and add lastline/lastcolumn to Pos
Also document let {}
@copumpkin

Copy link
Copy Markdown
Member

Don't leave us hanging! You want to make nix output more what? 😄

@Mathnerd314 Mathnerd314 changed the title Changes to make Nix output more Changes to make Nix output more informative errors Sep 11, 2015
@domenkozar

Copy link
Copy Markdown
Member

@edolstra didn't read the code itself, but this is worth persuing

@copumpkin

Copy link
Copy Markdown
Member

👍

@domenkozar

Copy link
Copy Markdown
Member

Another error that needs reasoning explanation:

error: access to path ‘/home/domen/nixpkgs/nixos/release-combined.nix’ is forbidden in restricted mode

It should at least say that it will evaluate nix only in search path and in Nix store.

@domenkozar

Copy link
Copy Markdown
Member

This would be so nice to have. @Mathnerd314 could you resolve merge errors and I'll test?

@Mathnerd314

Copy link
Copy Markdown
Contributor Author

I might update this eventually, but not anytime soon. There are some systematic design flaws which I want to resolve first.

@alesya-h

Copy link
Copy Markdown
Member

Any update on this?

@Mathnerd314

Mathnerd314 commented Apr 18, 2016 •

Copy link
Copy Markdown
Contributor Author

@alesguzik I've stopped most Nix development until June 24, 2016; you're welcome to do something with it before then though.

@domenkozar domenkozar added improvement UX The way in which users interact with Nix. Higher level than UI. labels Jul 21, 2016
@domenkozar

Copy link
Copy Markdown
Member

@Mathnerd314 would love to see this going, best to open one PR per fix. That way there is a higher chance they will get merged.

@copumpkin

Copy link
Copy Markdown
Member

@Mathnerd314 could you elaborate on

There are some systematic design flaws which I want to resolve first.

so someone else can pick this up effectively?

@Mathnerd314

Copy link
Copy Markdown
Contributor Author

@copumpkin That's just #296 and related issues; the only issue with this PR I know of is that I'm too lazy to update it to fix the merge conflicts. From Haskell it's clear that lazy evaluation works, and so far there's been nothing urgent enough in Nix development to force me to update. But of course anyone else is welcome to pick up the code and run with it.

@dtzWill

dtzWill commented May 22, 2018

Copy link
Copy Markdown
Member

This would be great! Has anyone looked at tackling the conflicts yet? Hopefully not too bad, but even if they are... breaking this into incremental improvements (as suggested above, and I agree should be done) means progress can be made without fixing all the things.

Is this likely to have costs to eval time/size? I've always assumed --show-trace existed (and was off by default) so that these costs were opt-in for debugging, but never actually checked how/if that's done. Also I have "show-trace = 1" or whatever in my nix.conf haha. Anyway, let's revive this!

@deliciouslytyped

Copy link
Copy Markdown

Is there any life left in this?

@stale

stale Bot commented Feb 13, 2021

Copy link
Copy Markdown

I marked this as stale due to inactivity. → More info

@stale stale Bot added the stale label Feb 13, 2021
@Ericson2314

Copy link
Copy Markdown
Member

I am sad this was neglected. I started looking to see if there was anything to salvage after our recent log overhauling.

@stale stale Bot removed the stale label Mar 1, 2022
@Ericson2314

Ericson2314 commented Mar 1, 2022 •

Copy link
Copy Markdown
Member

master...obsidiansystems:noisy-nix this is the first commit of this PR (without the color parts, as we have much more of that now) rebase and building but untested. That's enough for now.

@stale stale Bot added the stale label Sep 21, 2022
@fricklerhandwerk fricklerhandwerk added error-messages Confusing messages and better diagnostics and removed improvement labels Dec 5, 2022
@stale stale Bot removed the stale label Dec 9, 2022
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2022-12-09-nix-team-meeting-minutes-15/23951/1

@Ericson2314

Ericson2314 commented Feb 19, 2023 •

Copy link
Copy Markdown
Member

@layus Would you be able to help me understand what parts of this haven't been obviated by changes in the last few years --- I ask you in particular because your (merged) worked landing more error context seems related.

@layus

layus commented Feb 20, 2023 via email

Copy link
Copy Markdown
Member

@Ericson2314

Copy link
Copy Markdown
Member

Thanks for taking a look, @layus!

Comment thread src/libexpr/get-drvs.cc
Comment on lines +215 to +220
} catch (Error & e) {
e.addPrefix(format("while evaluating the attribute path ‘%1%’:\n") % attrPath);
if(!settings.keepGoing)
throw;
printMsg(lvlError, format(ANSI_RED "error:" ANSI_NORMAL " " "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
return false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is where the keepGoing stuff is, kind of a hack but it seemed to work in practice

Comment thread src/libutil/util.cc

string s = (format("%1%%2%\n") % prefix % fs.s).str();
if (!isatty(STDERR_FILENO)) s = filterANSIEscapes(s);
if (!isatty(STDERR_FILENO) && !useColor) s = filterANSIEscapes(s);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And this is the sole effect of the --color / -C / useColor option.

@Mathnerd314

Copy link
Copy Markdown
Contributor Author

As far as the improved locations there were various changes:

  • Pos had end line/column added. I guess this is a little hard to implement with the PosIdx structure, probably you would need a new Span type. The main issue is you have to change all the usages at once.
  • Positions were passed around in a lot more places. I think this is better in the current code, in particular the main change of storing positions in values seems to have made in Miscellaneous improvements for positioning in eval-errors #4440, at least for lambdas, applications, and attribute sets. I stored the position for all types of values but maybe that adds too much overhead. I never measured it explicitly but I didn't notice a big slowdown when I used the patch.
  • I systematically went through every place an error/trace was reported and made sure a position was passed. Probably this can be worked on incrementally / separately.
  • I added some more places that reported errors/traces, for example ExprVar::eval, forceValue, forceValueDeep on list positions, getDerivation, and callPrimOp. Again this can probably be its own PR.

@Ericson2314

Copy link
Copy Markdown
Member

Thanks for that summary, @Mathnerd314.

@fricklerhandwerk

Copy link
Copy Markdown
Contributor

Thanks @Mathnerd314, @layus, and @Ericson2314! We're on a good path away from getting overwhelmed with PRs and hopefully will slowly catch up with those stalled ones.

@tomberek

Copy link
Copy Markdown
Contributor

stale: re-open and re-base as needed

@tomberek tomberek closed this May 18, 2026
CertainLach pushed a commit to deltarocks/nix that referenced this pull request Sep 23, 2026
…ed-in-gc

Fix crash when GC is interrupted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error-messages Confusing messages and better diagnostics UX The way in which users interact with Nix. Higher level than UI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.