-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(remap): diagnostic error messages #6023
Conversation
12b879c
to
fe2f7df
Compare
b7d2e8f
to
cb820f0
Compare
Moving this back to draft, since I'm doing some internal changes to allow multiple diagnostics to be returned (and also in general improving the internal API design). cc #6027 |
4c2a879
to
1076a54
Compare
cb820f0
to
e1b81f5
Compare
let value = object | ||
.get(&self.path) | ||
.map_err(|e| E::from(Error::Resolve(e)))? | ||
.unwrap_or(Value::Null); | ||
let value = object.get(&self.path).ok().flatten().unwrap_or(Value::Null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged (some of) #5941 into this PR, as it made it easier to implement/test the changes in this PR.
Err("remap error: function error: unknown enum variant: baz, must be one of: foo, bar"), | ||
Ok(().into()), | ||
), | ||
// TODO: move to `remap-tests` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this PR and #6105 are merged, I'll be moving these tests to our UI testing set-up.
pub struct ParsedExpression { | ||
span: Span, | ||
expr: Expr, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, I want to encode span information into our Expr
type, but that proved to be a bigger change than needed right now.
.with_primary(format!("got: {}", got), arguments_span) | ||
.with_context(format!("expected: {} (at most)", max), arguments_span) | ||
} | ||
// TODO: have spans for each individual keyword |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I'll tackle in a follow-up PR.
# = hint: assign to "ok", without assigning to "err" | ||
# = see language documentation at: https://vector.dev/docs/reference/vrl/ | ||
|
||
ok, err = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reviewing, consider these early prototype messages.
The actual URLs, notes, and exact messages will be iterated on in future PRs. This PR's main purpose is to have the plumbing in place to allow us to improve these messages going forward.
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
60d09b5
to
153e1af
Compare
Signed-off-by: Jean Mertz <[email protected]>
span.clone(), | ||
); | ||
|
||
match () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, this would be nicer as an if .. else if .. else
.
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
.filter(|e| e.type_def(&state).is_fallible()) | ||
.for_each(|e| { | ||
diagnostics.push( | ||
Diagnostic::error("unhandled error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes the expression results in a runtime error because the function is a fallible one (eg. parse_json
). But other times it can because it has been passed a parameter that it can't determine is the correct type.
I think ultimately it would be nice to be able to distinguish between these. So for example with this:
if .ook == true { x = 2 } else { x = "boo" }
.thing = round(.x)
It would be nice for the error reporting to say :
error: unhandled error
┌─ :2:2
│
2 │ .thing = round(.x)
│ ^^^^^^^^^^^^^^^^^^
│ │
│ expression can't determine the correct types for the parameters and so may fail if it is passed
│ an incorrect type.
│ handle the error case to ensure runtime success
│
However that probably requires a bit of change to the fallibility checks to make fallibilty more than just a simple boolean, which would be out of scope for this PR.
Perhaps would could just change the below error message to say expression can result in runtime error, possibly because it can't determine the correct types for the parameters
? That would help point the user in the right direction without having to jump to the docs..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, as long as we use the try_boolean()
etc functions in the function implementation, this will already display something like unexpected type "string" for value
. But I agree that this can use a further refinement (specifically to mention the parameter name), and indeed it requires a bit more work that I considered to be outside the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Will all the commented out tests be moved out in a future PR, or is this still to do?
They will! See my earlier comment: #6023 (comment) |
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
This PR adds the initial infrastructure to support diagnostic error messages in VRL.
Given this source:
This is the diagnostic message returned by the compiler (running inside Vector):
I'm fairly happy how this ended up for the initial 0.12 release, but there's plenty of more to do here. I'll be filing separate issues to track future improvements.
On a high-level, here's what has changed:
Diagnostic
type (and friends) is introduced to record detailed information about an error.Program
now returnsResult<(Vec<Expression>, DiagnosticList), DiagnosticList>
. TheErr
case is returned if any of the diagnostic recorded are of level "error" or higher. TheOk
case only contains diagnostic messages of "warning" or lower (or none at all).Runtime
now returns a singleAbort
error if it failed to run. This is the case if you use!
in a function (e.g.parse_json!(.foo)
), which would satisfy the error-handling constraint at compile-time, but can still terminate the program at runtime.closes #4803
closes #6027