Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cue: ParsePath does not understand optional fields #3221

Open
myitcv opened this issue Jun 12, 2024 · 1 comment
Open

cue: ParsePath does not understand optional fields #3221

myitcv opened this issue Jun 12, 2024 · 1 comment

Comments

@myitcv
Copy link
Member

myitcv commented Jun 12, 2024

What version of CUE are you using (cue version)?

$ cue version
v0.9.0

Does this issue reproduce with the latest release?

Yes

What did you do?

go mod tidy
go run .
cmp stdout stdout.golden

-- go.mod --
module mod.example

go 1.22.3

require cuelang.org/go v0.9.0

-- main.go --
package main

import (
	"fmt"
	"log"

	"cuelang.org/go/cue"
)

func main() {
	path := cue.MakePath(cue.Def("values"), cue.Str("api").Optional())
	fmt.Printf("path: %v\n", path)
	roundTrip := cue.ParsePath(path.String())
	if err := roundTrip.Err(); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("roundTrip: %v\n", roundTrip)
}
-- stdout.golden --
path: #values.api?
roundTrip: #values.api?

What did you expect to see?

Passing test. The documentation for cue.ParsePath does not call out an exception for optional fields, so it seems reasonable to assume they can be parsed.

What did you see instead?

> go mod tidy
> go run .
[stdout]
path: #values.api?

[stderr]
main.go:15: expected 'EOF', found '?'
exit status 1

[exit status 1]
FAIL: /tmp/testscript1658982306/repro.txtar/script.txtar:2: unexpected go command failure
@mvdan
Copy link
Member

mvdan commented Jun 12, 2024

Note that required fields are likely affected by this as well.

And when the query extension is added (#165) we will need to be careful with this as well.

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

No branches or pull requests

2 participants