Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Mertz <git@jeanmertz.com>
  • Loading branch information
JeanMertz committed Mar 26, 2021
1 parent f4c6c5c commit 6417766
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/reference/remap.cue
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ remap: #Remap & {
"""
},
{
title: "Unhandled error"
title: "Unhandled fallible assignment"
input: log: message: "key1=value1 key2=value2"
source: """
structured = parse_key_value(.message)
"""
raises: compiletime: """
error[E103]: unhandled error
error[E103]: unhandled fallible assignment
┌─ :1:14
1 │ structured = parse_key_value(.message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package metadata

remap: errors: "103": {
title: "Unhandled error"
title: "Unhandled fallible assignment"
description: """
The right-hand side of this [assignment](\(urls.vrl_expressions)#\(remap.literals.regular_expression.anchor))
is fallible (that is, it can produce a [runtime error](\(urls.vrl_runtime_errors))), but the error isn't
Expand All @@ -17,30 +17,30 @@ remap: errors: "103": {
examples: [...{
input: log: message: "key=value"
source: #"""
. |= parse_key_value(.message)
. = parse_key_value(.message)
"""#
}]

examples: [
{
"title": "\(title) (coalescing)"
diff: #"""
-. |= parse_key_value(.message)
+. |= parse_key_value(.message) ?? {}
-. = parse_key_value(.message)
+. = parse_key_value(.message) ?? {}
"""#
},
{
"title": "\(title) (raising)"
diff: #"""
-. |= parse_key_value(.message)
+. |= parse_key_value!(.message)
-. = parse_key_value(.message)
+. = parse_key_value!(.message)
"""#
},
{
"title": "\(title) (assigning)"
diff: #"""
-. |= parse_key_value(.message)
+., err |= parse_key_value(.message)
-. = parse_key_value(.message)
+., err = parse_key_value(.message)
"""#
},
]
Expand Down
15 changes: 9 additions & 6 deletions lib/vrl/compiler/src/expression/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ impl Assignment {
// Fallible expressions require infallible assignment.
if type_def.is_fallible() {
return Err(Error {
variant: ErrorVariant::UnhandledError(target.to_string(), expr.to_string()),
variant: ErrorVariant::FallibleAssignment(
target.to_string(),
expr.to_string(),
),
span,
expr_span,
assignment_span,
Expand Down Expand Up @@ -444,8 +447,8 @@ pub enum ErrorVariant {
#[error("unnecessary no-op assignment")]
UnnecessaryNoop(Span),

#[error("unhandled error")]
UnhandledError(String, String),
#[error("unhandled fallible assignment")]
FallibleAssignment(String, String),

#[error("unnecessary error assignment")]
InfallibleAssignment(String, String, Span, Span),
Expand All @@ -472,7 +475,7 @@ impl DiagnosticError for Error {

match &self.variant {
UnnecessaryNoop(..) => 640,
UnhandledError(..) => 103,
FallibleAssignment(..) => 103,
InfallibleAssignment(..) => 104,
InvalidTarget(..) => 641,
}
Expand All @@ -487,7 +490,7 @@ impl DiagnosticError for Error {
Label::context("either assign to a path or variable here", *target_span),
Label::context("or remove the assignment", self.assignment_span),
],
UnhandledError(target, expr) => vec![
FallibleAssignment(target, expr) => vec![
Label::primary("this expression is fallible", self.expr_span),
Label::context("update the expression to be infallible", self.expr_span),
Label::context(
Expand All @@ -512,7 +515,7 @@ impl DiagnosticError for Error {
use ErrorVariant::*;

match &self.variant {
UnhandledError(..) | InfallibleAssignment(..) => vec![Note::SeeErrorDocs],
FallibleAssignment(..) | InfallibleAssignment(..) => vec![Note::SeeErrorDocs],
_ => vec![],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# object: { "message": "bananas and another ant" }
# result:
#
# error[E103]: unhandled error
# error[E103]: unhandled fallible assignment
# ┌─ :3:6
# │
# 3 │ .a = sha3(.result[0].an)
Expand Down

0 comments on commit 6417766

Please sign in to comment.