Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add errorlint linter. #346

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linters:
- bodyclose
- durationcheck
- errchkjson
- errorlint
- exportloopref
- gofmt
- goimports
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func loadConfig() (*config, []string, error) {
err = preIni.WriteFile(preCfg.ConfigFile,
flags.IniIncludeComments|flags.IniIncludeDefaults)
if err != nil {
err = fmt.Errorf("error creating a default config file: %v", err)
err = fmt.Errorf("error creating a default config file: %w", err)
fmt.Fprintln(os.Stderr, err)
return nil, nil, err
}
Expand Down Expand Up @@ -786,7 +786,7 @@ func loadConfig() (*config, []string, error) {
// Ensure the profiling address is a valid tcp address.
_, portStr, err := net.SplitHostPort(cfg.Profile)
if err != nil {
err := fmt.Errorf("invalid profile address: %s", err)
err := fmt.Errorf("invalid profile address: %w", err)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions dcrpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
var err error
p.hub, err = pool.NewHub(p.cancel, hcfg)
if err != nil {
return nil, fmt.Errorf("unable to initialize hub: %v", err)
return nil, fmt.Errorf("unable to initialize hub: %w", err)
}

err = p.hub.Connect(p.ctx)
if err != nil {
return nil, fmt.Errorf("unable to establish node connections: %v", err)
return nil, fmt.Errorf("unable to establish node connections: %w", err)
}

err = p.hub.FetchWork(p.ctx)
Expand Down
12 changes: 6 additions & 6 deletions pool/boltupgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func verifyV2Upgrade(t *testing.T, db *BoltDB) {
var share Share
err := json.Unmarshal(v, &share)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal share: %v",
return fmt.Errorf("%s: unable to unmarshal share: %w",
funcName, err)
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func verifyV3Upgrade(t *testing.T, db *BoltDB) {
var payment Payment
err := json.Unmarshal(v, &payment)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %v",
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

Expand Down Expand Up @@ -161,7 +161,7 @@ func verifyV3Upgrade(t *testing.T, db *BoltDB) {
var payment Payment
err := json.Unmarshal(v, &payment)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %v",
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func verifyV5Upgrade(t *testing.T, db *BoltDB) {
var share Share
err := json.Unmarshal(v, &share)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal share: %v",
return fmt.Errorf("%s: unable to unmarshal share: %w",
funcName, err)
}

Expand Down Expand Up @@ -269,7 +269,7 @@ func verifyV6Upgrade(t *testing.T, db *BoltDB) {
var pmt Payment
err := json.Unmarshal(v, &pmt)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %v",
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

Expand All @@ -295,7 +295,7 @@ func verifyV6Upgrade(t *testing.T, db *BoltDB) {
var pmt Payment
err := json.Unmarshal(v, &pmt)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal archived payment: %v",
return fmt.Errorf("%s: unable to unmarshal archived payment: %w",
funcName, err)
}

Expand Down
4 changes: 2 additions & 2 deletions pool/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 The Decred developers
// Copyright (c) 2019-2023 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -581,7 +581,7 @@ func (c *Client) handleSubmitWorkRequest(ctx context.Context, req *Request, allo
if !c.cfg.SoloPool {
err := c.claimWeightedShare()
if err != nil {
err := fmt.Errorf("%s: %v", id, err)
err := fmt.Errorf("%s: %w", id, err)
sErr := NewStratumError(Unknown, err)
resp := SubmitWorkResponse(*req.ID, false, sErr)
c.ch <- resp
Expand Down
5 changes: 2 additions & 3 deletions pool/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ func Test_BoltDB_FetchBucketHelpers(t *testing.T) {
if pbkt == nil {
pbkt, err = tx.CreateBucketIfNotExists(poolBkt)
if err != nil {
return fmt.Errorf("unable to create %s bucket: %v",
return fmt.Errorf("unable to create %s bucket: %w",
string(poolBkt), err)

}
vbytes := make([]byte, 4)
binary.LittleEndian.PutUint32(vbytes, BoltDBVersion)
err = pbkt.Put(versionK, vbytes)
if err != nil {
return fmt.Errorf("unable to persist version: %v", err)
return fmt.Errorf("unable to persist version: %w", err)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pool/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func NewHub(cancel context.CancelFunc, hcfg *HubConfig) (*Hub, error) {
if errors.Is(err, errs.ValueNotFound) {
err = hcfg.DB.persistPoolMode(cfgMode)
if err != nil {
return nil, fmt.Errorf("failed to persist pool mode: %v", err)
return nil, fmt.Errorf("failed to persist pool mode: %w", err)
}
dbMode = cfgMode
} else {
Expand Down Expand Up @@ -383,7 +383,7 @@ func (h *Hub) Connect(ctx context.Context) error {
keypair, err := tls.LoadX509KeyPair(h.cfg.WalletTLSCert,
h.cfg.WalletTLSKey)
if err != nil {
return fmt.Errorf("unable to read keypair: %v", err)
return fmt.Errorf("unable to read keypair: %w", err)
}
creds := credentials.NewTLS(&tls.Config{
Certificates: []tls.Certificate{keypair},
Expand Down
Loading