google / google/jsonnet

Better error message for newbie mistake +: vs :+

Open
#361 0 comments 2 reactions 0 assignees View on GitHub
enhancement error reporting
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

I don't think this is actually very important, but it was a source of confusion at some point so here it is.

It's quite easy to write something like:
```
{x: {y: 1}} {x:+ { z: 2 }}
```
It doesn't work and error message is mildly confusing:
```
RUNTIME ERROR: Unary operator + does not operate on type object
```

It's worse on integer types (that I initially got a problem with), but I suppose this is not what `+:` was designed for anyway:
```
{x: 1} { x :+ 42}
```
It doesn't fail, but the result is not what I expected:
```
{
"x": 42
}
```

I think it can be easily made better by lexing `:+` as a single token. Then a much more friendly static error would appear:
```
Expected one of :, ::, :::, +:, +::, +:::, got: :+
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.