Skip to content

Commit

Permalink
all: fix four previously ignored errors
Browse files Browse the repository at this point in the history
Spotted by staticcheck. Most are pretty simple; error variables we never
used, and caused no issues.

The openapi change is a bit trickier, since openapi test files include a
"$version" top-level field. For now, explicitly ignore that field, just
like we do with "-".

Change-Id: Ia062bcfad8d25a6f0d8cc114f4d5aee475775727
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6863
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mvdan authored and mpvl committed Sep 15, 2020
1 parent 60c207f commit 4c10692
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (c *Config) absDirFromImportPath(pos token.Pos, p importPath) (absDir, name
absDir = filepath.Join(GenPath(c.ModuleRoot), sub)
}

return absDir, name, nil
return absDir, name, err
}

// Complete updates the configuration information. After calling complete,
Expand Down
42 changes: 22 additions & 20 deletions encoding/openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,29 @@ func (c *Config) compose(inst *cue.Instance, schemas *ast.StructLit) (x *ast.Str
var info *ast.StructLit

for i, _ := inst.Value().Fields(cue.Definitions(true)); i.Next(); {
if !i.IsDefinition() {
label := i.Label()
attr := i.Value().Attribute("openapi")
if s, _ := attr.String(0); s != "" {
label = s
}
switch label {
case "-":
case "info":
info, _ = i.Value().Syntax().(*ast.StructLit)
if info == nil {
errs = errors.Append(errs, errors.Newf(i.Value().Pos(),
"info must be a struct"))
}
title, _ = i.Value().Lookup("title").String()
version, _ = i.Value().Lookup("version").String()

default:
if i.IsDefinition() {
continue
}
label := i.Label()
attr := i.Value().Attribute("openapi")
if s, _ := attr.String(0); s != "" {
label = s
}
switch label {
case "$version":
case "-":
case "info":
info, _ = i.Value().Syntax().(*ast.StructLit)
if info == nil {
errs = errors.Append(errs, errors.Newf(i.Value().Pos(),
"openapi: unsupported top-level field %q", x))
"info must be a struct"))
}
title, _ = i.Value().Lookup("title").String()
version, _ = i.Value().Lookup("version").String()

default:
errs = errors.Append(errs, errors.Newf(i.Value().Pos(),
"openapi: unsupported top-level field %q", label))
}
}

Expand Down Expand Up @@ -210,7 +212,7 @@ func (c *Config) compose(inst *cue.Instance, schemas *ast.StructLit) (x *ast.Str
"info", info,
"paths", ast.NewStruct(),
"components", ast.NewStruct("schemas", schemas),
), nil
), errs
}

// Schemas extracts component/schemas from the CUE top-level types.
Expand Down
3 changes: 3 additions & 0 deletions internal/cuetest/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func Run(t *testing.T, dir, command string, cfg *Config) {
cfg.Stdout = buf
}
cmd, err := cmd.New(args)
if err != nil {
t.Fatal(err)
}
if cfg.Stdout != nil {
cmd.SetOutput(cfg.Stdout)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func Log2(x *internal.Decimal) (*internal.Decimal, error) {
return &d, err
}
_, err = apdContext.Quo(&d, &d, &ln2)
return &d, nil
return &d, err
}

// Log1p returns the natural logarithm of 1 plus its argument x.
Expand Down

0 comments on commit 4c10692

Please sign in to comment.