chore: use errors.New() instead of fmt.Errorf()

This commit is contained in:
Vincent Bernat
2025-07-29 07:42:31 +02:00
parent 18beb310ee
commit 5e669db4b3
5 changed files with 10 additions and 7 deletions

View File

@@ -4,7 +4,7 @@
package daemon
import (
"fmt"
"errors"
"testing"
"time"
@@ -87,7 +87,7 @@ func TestTombTracking(t *testing.T) {
case <-tomb.Dying():
t.Fatalf("Dying() should not happen inside the tomb")
case <-ch:
return fmt.Errorf("crashing")
return errors.New("crashing")
}
return nil
})

View File

@@ -5,6 +5,7 @@ package clickhouse
import (
"context"
"errors"
"fmt"
"net"
"strings"
@@ -66,7 +67,7 @@ func (c *Component) migrateDatabase() error {
return fmt.Errorf("unable to parse cluster settings: %w", err)
}
if shardNum == 0 {
return fmt.Errorf("cannot get the number of shards for the cluster")
return errors.New("cannot get the number of shards for the cluster")
}
c.shards = int(shardNum)
}

View File

@@ -5,6 +5,7 @@
package clickhouse
import (
"errors"
"fmt"
"os"
"sort"
@@ -84,7 +85,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende
return c.config.Resolutions[i].Interval < c.config.Resolutions[j].Interval
})
if len(c.config.Resolutions) == 0 || c.config.Resolutions[0].Interval != 0 {
return nil, fmt.Errorf("resolutions need to be configured, including interval: 0")
return nil, errors.New("resolutions need to be configured, including interval: 0")
}
c.d.Daemon.Track(&c.t, "orchestrator/clickhouse")

View File

@@ -5,6 +5,7 @@ package gnmi
import (
"context"
"errors"
"fmt"
"net"
"net/netip"
@@ -333,5 +334,5 @@ func (p *Provider) detectModelAndEncoding(ctx context.Context, tg *target.Target
return model, encoding, nil
}
}
return Model{}, "", fmt.Errorf("no compatible model found")
return Model{}, "", errors.New("no compatible model found")
}

View File

@@ -117,7 +117,7 @@ func (p *Provider) Poll(ctx context.Context, exporter, agent netip.Addr, port ui
results = slices.Clone(currentResult.Variables)
} else {
if len(results) != len(currentResult.Variables) {
logError(fmt.Errorf("SNMP mismatch on variable lengths"))
logError(errors.New("SNMP mismatch on variable lengths"))
}
for idx := range results {
switch results[idx].Type {
@@ -128,7 +128,7 @@ func (p *Provider) Poll(ctx context.Context, exporter, agent netip.Addr, port ui
}
}
if len(results) != len(requests) {
logError(fmt.Errorf("SNMP mismatch on variable lengths"))
logError(errors.New("SNMP mismatch on variable lengths"))
}
p.metrics.times.WithLabelValues(exporterStr).Observe(time.Since(start).Seconds())