Skip to content

Commit

Permalink
Print error messages but not traces
Browse files Browse the repository at this point in the history
This makes output of values that include errors much cleaner.

Before:
```
nix-repl> { err = builtins.throw "uh oh!"; }
{ err = «error:
       … while calling the 'throw' builtin
         at «string»:1:9:
            1| { err = builtins.throw "uh oh!"; }
             |         ^

       error: uh oh!»; }
```

After:
```
nix-repl> { err = builtins.throw "uh oh!"; }
{ err = «error: uh oh!»; }
```

But if the whole expression throws an error, source locations and (if
applicable) a stack trace are printed, like you'd expect:

```
nix-repl> builtins.throw "uh oh!"
error:
       … while calling the 'throw' builtin
         at «string»:1:1:
            1| builtins.throw "uh oh!"
             | ^

       error: uh oh!
```
  • Loading branch information
9999years committed Feb 4, 2024
1 parent 49cf090 commit fde9417
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libexpr/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class Printer
{
if (options.ansiColors)
output << ANSI_RED;
output << "«" << e.msg() << "»";
output << "«error: " << e.info().msg << "»";
if (options.ansiColors)
output << ANSI_NORMAL;
}
Expand Down

0 comments on commit fde9417

Please sign in to comment.