Skip to content

fix: return null if parseYaml does not yield any result#841

Merged
johnbartholomew merged 1 commit intogoogle:masterfrom
netomi:fix-parse-yaml
Jan 30, 2026
Merged

fix: return null if parseYaml does not yield any result#841
johnbartholomew merged 1 commit intogoogle:masterfrom
netomi:fix-parse-yaml

Conversation

@netomi
Copy link
Copy Markdown
Contributor

@netomi netomi commented Jan 30, 2026

This fixes #714 .

The documentation is not clear what shall happen when parsing a yaml string does not result in anything.
The fix now uses null as return value, which would be consistent with jrsonnet for this example.

An empty object would also be reasonable imho.

btw. the same problem exists for parseJson.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 44.348% (+0.01%) from 44.335%
when pulling ad1fccb on netomi:fix-parse-yaml
into fb1ca81 on google:master.

@johnbartholomew
Copy link
Copy Markdown
Collaborator

As the original bug report notes, it's not really clear what the output should be. I can see arguments for producing an error (but not a Go panic/internal error!), returning null, maybe even other things.

It looks like std.parseJson produces an error if given empty input:

$ go run ./cmd/jsonnet -e 'std.parseJson("")'
RUNTIME ERROR: failed to parse JSON: unexpected end of JSON input
	<cmdline>:1:1-18	$
	During evaluation

Anyway, I guess null is ok, so I'll go ahead with this.

@johnbartholomew johnbartholomew merged commit 9635d56 into google:master Jan 30, 2026
9 checks passed
@He-Pin
Copy link
Copy Markdown
Contributor

He-Pin commented Jan 31, 2026

in sjsonnet, it's {}, but I think null is right here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants