-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print the value in
error: cannot coerce
messages (#9553)
* Print the value in `error: cannot coerce` messages This extends the `error: cannot coerce a TYPE to a string` message to print the value that could not be coerced. This helps with debugging by making it easier to track down where the value is being produced from, especially in errors with deep or unhelpful stack traces. Co-authored-by: Valentin Gagarin <[email protected]>
- Loading branch information
1 parent
1399829
commit f0ac2a3
Showing
6 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
synopsis: Coercion errors include the failing value | ||
issues: #561 | ||
prs: #9553 | ||
description: { | ||
|
||
The `error: cannot coerce a <TYPE> to a string` message now includes the value which caused the error. | ||
|
||
Previously, a failed string coercion produced a confusing error message if the trace didn't show where the offending value was defined: | ||
|
||
```bash | ||
$ nix-instantiate --eval --expr ' | ||
let x = { a = 1; }; in | ||
"${x}" | ||
' | ||
error: | ||
… while evaluating a path segment | ||
|
||
at «string»:4:2: | ||
|
||
3| | ||
4| "${x}" | ||
| ^ | ||
5| | ||
|
||
error: cannot coerce a set to a string | ||
``` | ||
Now, the error message includes the value itself: | ||
```bash | ||
$ nix-instantiate --eval --expr ' | ||
let x = { a = 1; }; in | ||
"${x}" | ||
' | ||
error: | ||
… while evaluating a path segment | ||
|
||
at «string»:4:2: | ||
|
||
3| | ||
4| "${x}" | ||
| ^ | ||
5| | ||
|
||
error: cannot coerce a set to a string: { a = 1; } | ||
``` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ error: | |
| ^ | ||
2| | ||
|
||
error: cannot coerce a function to a string | ||
error: cannot coerce a function to a string: <LAMBDA> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ error: | |
| ^ | ||
2| | ||
|
||
error: cannot coerce a function to a string | ||
error: cannot coerce a function to a string: <LAMBDA> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters