Skip to content

Commit

Permalink
Add missing URL and reduce line length (#9689)
Browse files Browse the repository at this point in the history
Signed-off-by: Luc Perkins <luc.perkins@datadoghq.com>
  • Loading branch information
lucperkins authored Oct 19, 2021
1 parent b100f78 commit fcb8c79
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions website/content/en/docs/reference/vrl/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ short: Errors
weight: 2
---

VRL is a [fail-safe][fail_safety] language, which means that a VRL program doesn't compile unless every potential error is handled. Observability data is notoriously unpredictable and fail safety ensures that your VRL programs elegantly handle malformed data.
VRL is a [fail-safe][fail_safety] language, which means that a VRL program doesn't compile unless
every potential error is handled. Observability data is notoriously unpredictable and fail safety
ensures that your VRL programs elegantly handle malformed data.

## Compile-time errors

{{< vrl/errors/compile-time >}}

## Runtime errors

A runtime error occurs after compilation and during program runtime. Because VRL is fail safe, runtime error must be [handled](#handling). This forces you to address how VRL programs should respond to errors.
A runtime error occurs after compilation and during program runtime. Because VRL is fail safe, all
runtime errors must be [handled](#handling). This forces you to address how VRL programs should
respond to errors.

Runtime errors are strings that describe the error.

Expand All @@ -26,7 +30,8 @@ You have three options for handling errors in VRL:

#### Assigning

As documented in the [assignment expression reference], you can **assign** errors when invoking an expression that's fallible. When assigned, runtime errors are simple strings:
As documented in the [assignment expression reference][assign], you can **assign** errors when
invoking an expression that's fallible. When assigned, runtime errors are simple strings:

```coffee
structured, err = parse_json("not json")
Expand All @@ -50,9 +55,12 @@ if err == null {
}
```

The above example compiles because `foo` will either be assigned the integer representation of `.foo` if it can be coerced to an integer, or it will be set to the "empty integer value" `0` if `.foo` can't be coerced into an integer.
The above example compiles because `foo` will either be assigned the integer representation of
`.foo` if it can be coerced to an integer, or it will be set to the "empty integer value" `0` if
`.foo` can't be coerced into an integer.

Because of this, it is important to always check if `err` is null before using the `ok` value of an infallible assignment.
Because of this, it is important to always check whether `err` is null before using the `ok` value
of an infallible assignment.

##### Empty values

Expand All @@ -70,7 +78,8 @@ Null | `null`

#### Coalescing

As documented in the [coalesce expression reference][coalesce], you can **coalesce** errors to efficiently step through multiple expressions:
As documented in the [coalesce expression reference][coalesce], you can **coalesce** errors to
efficiently step through multiple expressions:

```coffee
structured = parse_json("not json") ?? parse_syslog("not syslog") ?? {}
Expand All @@ -79,15 +88,18 @@ structured = parse_json("not json") ?? parse_syslog("not syslog") ?? {}

#### Raising

As documented in the [function call reference][call], you can **raise** errors to immediately abort the program by adding a `!` to the end of the function name:
As documented in the [function call reference][call], you can **raise** errors to immediately abort
the program by adding a `!` to the end of the function name:

```coffee
structured = parse_json!("not json")
. = merge(., structured)
```

{{< warning title="Raising errors should be used with caution" >}}
While raising errors can simplfy your program, you should think carefully before aborting your program. If this operation is critical to the structure of your data you should abort, otherwise consider handling the error and proceeding with the rest of your program.
While raising errors can simplfy your program, you should think carefully before aborting your
program. If this operation is critical to the structure of your data you should abort, otherwise
consider handling the error and proceeding with the rest of your program.
{{< /warning >}}

[assign]: /docs/reference/vrl/expressions/#assignment
Expand Down

0 comments on commit fcb8c79

Please sign in to comment.