Fix all golangci-lint errcheck and unused warnings
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-tests Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

- Wrap defer resp.Body.Close() to capture error
- Ignore json.Unmarshal error in valueAny (best-effort)
- Check enc.Encode and os.Stdout.Write return values
- Check json.NewEncoder.Encode and w.Write in test helpers
- Check os.MkdirAll and os.WriteFile errors in tests
- Check first writeDefaultConfig() call in AlreadyExists test
- Remove unused mustMarshal helper
This commit is contained in:
2026-03-25 17:40:40 +11:00
parent 0ba9a3da09
commit c4cdfd2cc1
2 changed files with 27 additions and 21 deletions
+4 -4
View File
@@ -150,7 +150,7 @@ func queryPuppetDB(puppetDBURL, query string) ([]fact, error) {
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
@@ -176,7 +176,7 @@ func valueString(raw json.RawMessage) string {
func valueAny(raw json.RawMessage) interface{} {
var v interface{}
json.Unmarshal(raw, &v)
_ = json.Unmarshal(raw, &v)
return v
}
@@ -280,7 +280,7 @@ func run(cfg config, nodeName, factName, match, partialMatch string, showRole, n
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.SetEscapeHTML(false)
enc.Encode(hostFactMap)
_ = enc.Encode(hostFactMap)
case count:
values := stdinLines
@@ -299,7 +299,7 @@ func run(cfg config, nodeName, factName, match, partialMatch string, showRole, n
"all": map[string]interface{}{"hosts": hosts},
}
b, _ := yaml.Marshal(inventory)
os.Stdout.Write(b)
_, _ = os.Stdout.Write(b)
case nodeOnly:
for _, line := range returnData {