vector icon indicating copy to clipboard operation
vector copied to clipboard

VRL: Diagnostics point to wrong expression for fallibility error

Open fuchsnj opened this issue 3 years ago • 4 comments

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

In the following example, the push(.x, 1) is fallible, but the diagnostic error points to the incorrect expression.

{
   .a=1
   push(.x,1)
   .b=2
}

error[E103]: unhandled fallible assignment
  ┌─ :4:7
  │
4 │    .b=2
  │    -- ^
  │    │  │
  │    │  this expression is fallible
  │    │  update the expression to be infallible
  │    or change this to an infallible assignment:
  │    .b, err = 2
  │
  = see documentation about error handling at https://errors.vrl.dev/#handling
  = learn more about error code 103 at https://errors.vrl.dev/103
  = see language documentation at https://vrl.dev

Version

0.23.0

fuchsnj avatar Aug 01 '22 19:08 fuchsnj

This is likely related to https://github.com/vectordotdev/vector/pull/12880

fuchsnj avatar Aug 01 '22 19:08 fuchsnj

This also affects arrays

$ x,err = [{.a=1}, push(.x, 1), {.b=2}]

error[E103]: unhandled fallible assignment
  ┌─ :1:35
  │
1 │ x,err = [{.a=1}, push(.x, 1), {.b=2}]
  │                                -- ^
  │                                │  │
  │                                │  this expression is fallible
  │                                │  update the expression to be infallible
  │                                or change this to an infallible assignment:
  │                                .b, err = 2
  │
  = see documentation about error handling at https://errors.vrl.dev/#handling
  = learn more about error code 103 at https://errors.vrl.dev/103
  = see language documentation at https://vrl.dev

fuchsnj avatar Aug 01 '22 20:08 fuchsnj

... and arbitrary operators

$ {push(.x, 1); true} || {.a = 1}
error[E103]: unhandled fallible assignment
  ┌─ :1:30
  │
1 │ {push(.x, 1); true} || {.a = 1}
  │                         ---- ^
  │                         │    │
  │                         │    this expression is fallible
  │                         │    update the expression to be infallible
  │                         or change this to an infallible assignment:
  │                         .a, err = 1
  │
  = see documentation about error handling at https://errors.vrl.dev/#handling
  = learn more about error code 103 at https://errors.vrl.dev/103
  = see language documentation at https://vrl.dev

fuchsnj avatar Aug 01 '22 20:08 fuchsnj

Here is an example that compiles fine on 0.22.1 but fails to compile on 0.23.0

ok,err = {.a=1; push(.x, 1); .b=2}
error[E103]: unhandled fallible assignment
  ┌─ :1:33
  │
1 │ ok,err = {.a=1; push(.x, 1); .b=2}
  │                              -- ^
  │                              │  │
  │                              │  this expression is fallible
  │                              │  update the expression to be infallible
  │                              or change this to an infallible assignment:
  │                              .b, err = 2
  │
  = see documentation about error handling at https://errors.vrl.dev/#handling
  = learn more about error code 103 at https://errors.vrl.dev/103
  = see language documentation at https://vrl.dev/

fuchsnj avatar Aug 02 '22 15:08 fuchsnj