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

cmd/cue: exp gengotypes emits unhelpful error given a packageless CUE file #3764

Open
jpluscplusm opened this issue Feb 17, 2025 · 1 comment
Assignees
Labels

Comments

@jpluscplusm
Copy link
Collaborator

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

$ cue version
cue version v0.13.0-0.dev.0.20250217140725-3545df15d578

go version go1.23.5
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.13.0

Does this issue reproduce with the latest stable release?

Yes, v0.12.0.

What did you do?

! exec cue exp gengotypes file.cue
! stderr 'expected ''IDENT'', found ''type'''
-- file.cue --
#X: {
  y: int
  z: string
}

What did you expect to see?

A passing test, indicating a friendlier error message that told me what I'd done to trigger the error.

What did you see instead?

> ! exec cue exp gengotypes file.cue
[stderr]
-- $WORK/cue_types_gen.go --
   1: // Code generated by "cue exp gengotypes"; DO NOT EDIT.
   2: 
   3: package 
   4: 
   5: type X struct {
   6: Y int64 `json:"y"`
   7: 
   8: Z string `json:"z"`
   9: 
  10: }
  11: 
  12: 

--
5:1: expected 'IDENT', found 'type'
[exit status 1]
> ! stderr 'expected ''IDENT'', found ''type'''
FAIL: cue.exp.gengotypes.packagelessFilesErrorIsUnhelpful.txtar:2: unexpected match for `expected 'IDENT', found 'type'` found in stderr: expected 'IDENT', found 'type'
@jpluscplusm jpluscplusm added NeedsInvestigation Triage Requires triage/attention labels Feb 17, 2025
@jpluscplusm jpluscplusm changed the title cmd/cue: unhelpful error message when exp-gengotypes fails to process a packageless CUE file cmd/cue: exp gengotypes emits unhelpful error given a packageless CUE file Feb 17, 2025
@mvdan mvdan self-assigned this Feb 20, 2025
@mvdan
Copy link
Member

mvdan commented Feb 20, 2025

My thinking is to make this a nicer error, but still fail, because currently the CUE package name is crucial to know what filename to output to - and also what to name the resulting Go package.

@mvdan mvdan added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants