Skip to content

Commit

Permalink
cmd/cue/cmd: do not silently ignore unknown filetypes
Browse files Browse the repository at this point in the history
Fixes #688

Change-Id: Ieb476c75c85ce213ace16a2411e492c524752ad2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9568
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 29, 2021
1 parent 2e1ac0f commit 97cac92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_filetypes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
! cue eval cue+date: x.cue
stderr 'unknown filetype date'
-- x.cue --
a: 5
26 changes: 20 additions & 6 deletions internal/filetypes/filetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func ParseArgs(args []string) (files []*build.File, err error) {
hasFiles = true
continue
}
inst, v = parseType("", Input)
inst, v, err = parseType("", Input)
if err != nil {
return nil, err
}
}
f, err := toFile(inst, v, s)
if err != nil {
Expand All @@ -202,7 +205,10 @@ func ParseArgs(args []string) (files []*build.File, err error) {
case qualifier != "" && !hasFiles:
return nil, errors.Newf(token.NoPos, "scoped qualifier %q without file", qualifier+":")
}
inst, v = parseType(a[0], Input)
inst, v, err = parseType(a[0], Input)
if err != nil {
return nil, err
}
qualifier = a[0]
hasFiles = false
}
Expand Down Expand Up @@ -233,7 +239,10 @@ func ParseFile(s string, mode Mode) (*build.File, error) {
return nil, errors.Newf(token.NoPos, "empty file name in %q", s)
}

inst, val := parseType(scope, mode)
inst, val, err := parseType(scope, mode)
if err != nil {
return nil, err
}
return toFile(inst, val, file)
}

Expand Down Expand Up @@ -273,7 +282,7 @@ func toFile(i, v cue.Value, filename string) (*build.File, error) {
return f, nil
}

func parseType(s string, mode Mode) (inst, val cue.Value) {
func parseType(s string, mode Mode) (inst, val cue.Value, err error) {
i := cuegenInstance.Value()
i = i.Unify(i.Lookup("modes", mode.String()))
v := i.LookupDef("File")
Expand All @@ -283,10 +292,15 @@ func parseType(s string, mode Mode) (inst, val cue.Value) {
if p := strings.IndexByte(t, '='); p >= 0 {
v = v.Fill(t[p+1:], "tags", t[:p])
} else {
v = v.Unify(i.Lookup("tags", t))
info := i.Lookup("tags", t)
if !info.Exists() {
return inst, val, errors.Newf(token.NoPos,
"unknown filetype %s", t)
}
v = v.Unify(info)
}
}
}

return i, v
return i, v, nil
}

0 comments on commit 97cac92

Please sign in to comment.