Skip to content

Commit 1ac74ac

Browse files
committed
internal/encoding/yaml: attach a filename position to an empty file "null"
As otherwise any reported errors are missing the filename. There is no line or column information, which is fine, as this is an empty YAML file where the null was not actually spelled out. Seems to slightly improve a JSON Schema decoding error as well. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Iadee9aea7431786fbdfeddb25d2b6a31a77a6f4f Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211414 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 91e843b commit 1ac74ac

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

cmd/cue/cmd/testdata/script/empty_yaml.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cmp stderr export-all.stderr
1313
null
1414
-- export-all.stderr --
1515
conflicting values null and {two:"two text"} (mismatched types null and struct):
16-
16+
./empty.yaml
1717
./two.yaml:1:1
1818
-- one.yaml --
1919
one: "one text"

encoding/jsonschema/testdata/txtar/openapi_nonexistent_error.txtar

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Test what happens when there's an OpenAPI schema that has no
66
-- schema.yaml --
77
-- out/decode/extract --
88
ERROR:
9-
root value at path #/components/schemas/ does not exist
9+
root value at path #/components/schemas/ does not exist:
10+
schema.yaml

internal/encoding/yaml/decode.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ func (d *decoder) Decode() (ast.Expr, error) {
108108
// with a null scalar value inside instead.
109109
if !d.yamlNonEmpty {
110110
return &ast.BasicLit{
111-
Kind: token.NULL,
112-
Value: "null",
111+
Kind: token.NULL,
112+
ValuePos: d.tokFile.Pos(0, token.NoRelPos),
113+
Value: "null",
113114
}, nil
114115
}
115116
// If the input wasn't empty, we already decoded some CUE syntax nodes,

0 commit comments

Comments
 (0)