all: fix four previously ignored errors
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>
diff --git a/cue/load/config.go b/cue/load/config.go
index a81ce95..6a84732 100644
--- a/cue/load/config.go
+++ b/cue/load/config.go
@@ -395,7 +395,7 @@
absDir = filepath.Join(GenPath(c.ModuleRoot), sub)
}
- return absDir, name, nil
+ return absDir, name, err
}
// Complete updates the configuration information. After calling complete,
diff --git a/encoding/openapi/openapi.go b/encoding/openapi/openapi.go
index f26cff6..6eaebb8 100644
--- a/encoding/openapi/openapi.go
+++ b/encoding/openapi/openapi.go
@@ -133,27 +133,29 @@
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))
}
}
@@ -210,7 +212,7 @@
"info", info,
"paths", ast.NewStruct(),
"components", ast.NewStruct("schemas", schemas),
- ), nil
+ ), errs
}
// Schemas extracts component/schemas from the CUE top-level types.
diff --git a/internal/cuetest/sim.go b/internal/cuetest/sim.go
index 2d527ac..51aa95d 100644
--- a/internal/cuetest/sim.go
+++ b/internal/cuetest/sim.go
@@ -65,6 +65,9 @@
cfg.Stdout = buf
}
cmd, err := cmd.New(args)
+ if err != nil {
+ t.Fatal(err)
+ }
if cfg.Stdout != nil {
cmd.SetOutput(cfg.Stdout)
} else {
diff --git a/pkg/math/math.go b/pkg/math/math.go
index 772d0af..ec27429 100644
--- a/pkg/math/math.go
+++ b/pkg/math/math.go
@@ -386,7 +386,7 @@
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.