-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve location reporting for type and type coercion errors #6200
Comments
/cc @kamadorueda . Someone told me you are working on improving error messages, and could want to have a look at this one ;-) |
Well, I am wrong, we do have an Expr, but not all Expr have a position to use for error reporting. I wonder if it is a deliberate design decision. I wonder if |
My working hypothesis is that the It would then look like:
Not 100% there, but already an improvement. Ideally, the primops can get a
or perhaps even printing the function and argument Pos both, separately. Here the function context is quite clear, but that may not always be the case? |
Not really valid. the result of the call So either add a Pos to every Expr, or provide a message that works in the absence of a proper pos.
If we print the argument position, we will automatically have the function position, as each function call gets a trace frame in the debug. |
Another example;
|
Oh, actually first intuition was right. We only have an Expr when we use evalXXX fucntions, but forceXXX functions do not have that property. Back to the first idea then. |
Describe the bug
Nix sometimes reports imprecise error location when a value has the wrong type for an operation.
In this example, builtins.hasAttr expects a string and receives a boolean as first argument. But the caret points at the builtin itself, making the error message misleading.
In the code, we see that we coerce the first arg to a string, and pass as trace position the
pos
of the builtin itsefl (the only we can have at this point in evaluation).nix/src/libexpr/primops.cc
Line 2206 in 3144b37
Expected behavior
Each time we have a coercion, there is a potential for failure. We should ensure that the message is correct by pointing at the right location. From my analysis, it is next to impossible, as the information is lost by the time we know that we have to coerce.
The next best thing is to amend the error message to mention how the error relates to the error location. In this case, say it is the first argument to the builtin under evaluation. This way, the caret can remain on the builtin itself.
error: in the first argument of builtins.hasAttr: value is a Boolean while a string was expected
Thus, coercion functions such as
coerceToString
,evalAttrs
and the like should take an extra, mandatory error message describing what the coerced value means for the current Expr node under evaluation.We should also ensure that each
Expr
node that may fail in such a way gets a proper error context. That is, we should ensure that a caret points to the expression we refer to in the error message. This is the issue encountered by #6191.Additional context
#6191
9d67332 (thanks @greedy !)
The text was updated successfully, but these errors were encountered: