Fix all golangci-lint errcheck and unused warnings
- 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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user