Skip to content

Commit

Permalink
chore(linters): add errorlint (#3334)
Browse files Browse the repository at this point in the history
Adds errorlint linter and fixes related issues
  • Loading branch information
walldiss authored Apr 29, 2024
1 parent a25773c commit b241223
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 69 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linters:
- dogsled
- dupl
- errcheck
- errorlint
# - funlen
# - gochecknoglobals
# - gochecknoinits
Expand Down
7 changes: 4 additions & 3 deletions api/gateway/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gateway

import (
"encoding/json"
"errors"
"net/http"
"strconv"

Expand Down Expand Up @@ -33,8 +34,8 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
}

err = h.share.SharesAvailable(r.Context(), header)
switch err {
case nil:
switch {
case err == nil:
resp, err := json.Marshal(&AvailabilityResponse{Available: true})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
Expand All @@ -44,7 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
if werr != nil {
log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err)
}
case share.ErrNotAvailable:
case errors.Is(err, share.ErrNotAvailable):
resp, err := json.Marshal(&AvailabilityResponse{Available: false})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
Expand Down
6 changes: 3 additions & 3 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ func (s *Service) Included(
return blob.compareCommitments(commitment)
}}
_, resProof, err := s.retrieve(ctx, height, namespace, sharesParser)
switch err {
case nil:
case ErrBlobNotFound:
switch {
case err == nil:
case errors.Is(err, ErrBlobNotFound):
return false, nil
default:
return false, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func InitClient(cmd *cobra.Command, _ []string) error {

storePath, err := getStorePath(cmd)
if err != nil {
return fmt.Errorf("%s: %v", rootErrMsg, err)
return fmt.Errorf("%s: %w", rootErrMsg, err)
}

cfg, err := nodebuilder.LoadConfig(filepath.Join(storePath, "config.toml"))
if err != nil {
return fmt.Errorf("%s: root directory was not specified: %v", rootErrMsg, err)
return fmt.Errorf("%s: root directory was not specified: %w", rootErrMsg, err)
}

if requestURL == "" {
Expand All @@ -66,7 +66,7 @@ func InitClient(cmd *cobra.Command, _ []string) error {
} else {
token, err := getToken(storePath)
if err != nil {
return fmt.Errorf("%s: %v", rootErrMsg, err)
return fmt.Errorf("%s: %w", rootErrMsg, err)
}

authTokenFlag = token
Expand Down
3 changes: 2 additions & 1 deletion das/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package das

import (
"context"
"errors"

libhead "github.com/celestiaorg/go-header"

Expand All @@ -25,7 +26,7 @@ func (s *subscriber) run(ctx context.Context, sub libhead.Subscription[*header.E
for {
h, err := sub.NextHeader(ctx)
if err != nil {
if err == context.Canceled {
if errors.Is(err, context.Canceled) {
return
}

Expand Down
20 changes: 10 additions & 10 deletions nodebuilder/blob/cmd/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ var getCmd = &cobra.Command{

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("error parsing a height:%v", err)
return fmt.Errorf("error parsing a height: %w", err)
}

namespace, err := cmdnode.ParseV0Namespace(args[1])
if err != nil {
return fmt.Errorf("error parsing a namespace:%v", err)
return fmt.Errorf("error parsing a namespace: %w", err)
}

commitment, err := base64.StdEncoding.DecodeString(args[2])
if err != nil {
return fmt.Errorf("error parsing a commitment:%v", err)
return fmt.Errorf("error parsing a commitment: %w", err)
}

blob, err := client.Blob.Get(cmd.Context(), height, namespace, commitment)
Expand All @@ -109,12 +109,12 @@ var getAllCmd = &cobra.Command{

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("error parsing a height:%v", err)
return fmt.Errorf("error parsing a height: %w", err)
}

namespace, err := cmdnode.ParseV0Namespace(args[1])
if err != nil {
return fmt.Errorf("error parsing a namespace:%v", err)
return fmt.Errorf("error parsing a namespace: %w", err)
}

blobs, err := client.Blob.GetAll(cmd.Context(), height, []share.Namespace{namespace})
Expand Down Expand Up @@ -224,12 +224,12 @@ var submitCmd = &cobra.Command{
func getBlobFromArguments(namespaceArg, blobArg string) (*blob.Blob, error) {
namespace, err := cmdnode.ParseV0Namespace(namespaceArg)
if err != nil {
return nil, fmt.Errorf("error parsing a namespace:%v", err)
return nil, fmt.Errorf("error parsing a namespace: %w", err)
}

parsedBlob, err := blob.NewBlobV0(namespace, []byte(blobArg))
if err != nil {
return nil, fmt.Errorf("error creating a blob:%v", err)
return nil, fmt.Errorf("error creating a blob: %w", err)
}

return parsedBlob, nil
Expand All @@ -248,17 +248,17 @@ var getProofCmd = &cobra.Command{

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("error parsing a height:%v", err)
return fmt.Errorf("error parsing a height: %w", err)
}

namespace, err := cmdnode.ParseV0Namespace(args[1])
if err != nil {
return fmt.Errorf("error parsing a namespace:%v", err)
return fmt.Errorf("error parsing a namespace: %w", err)
}

commitment, err := base64.StdEncoding.DecodeString(args[2])
if err != nil {
return fmt.Errorf("error parsing a commitment:%v", err)
return fmt.Errorf("error parsing a commitment: %w", err)
}

proof, err := client.Blob.GetProof(cmd.Context(), height, namespace, commitment)
Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/header/cmd/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var getByHashCmd = &cobra.Command{

hash, err := hex.DecodeString(args[0])
if err != nil {
return fmt.Errorf("error decoding a hash: expected a hex encoded string:%v", err)
return fmt.Errorf("error decoding a hash: expected a hex encoded string: %w", err)
}
header, err := client.Header.GetByHash(cmd.Context(), hash)
return cmdnode.PrintOutput(header, err, nil)
Expand All @@ -92,7 +92,7 @@ var getByHeightCmd = &cobra.Command{

height, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("error parsing a height:%v", err)
return fmt.Errorf("error parsing a height: %w", err)
}

header, err := client.Header.GetByHeight(cmd.Context(), height)
Expand Down
3 changes: 2 additions & 1 deletion nodebuilder/header/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package header

import (
"context"
"errors"
"fmt"

libhead "github.com/celestiaorg/go-header"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (s *Service) Subscribe(ctx context.Context) (<-chan *header.ExtendedHeader,
for {
h, err := subscription.NextHeader(ctx)
if err != nil {
if err != context.DeadlineExceeded && err != context.Canceled {
if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) {
log.Errorw("fetching header from subscription", "err", err)
}
return
Expand Down
6 changes: 3 additions & 3 deletions nodebuilder/p2p/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Listen(listen []string) func(h hst.Host) (err error) {
for i, addr := range listen {
maListen[i], err = ma.NewMultiaddr(addr)
if err != nil {
return fmt.Errorf("failure to parse config.P2P.ListenAddresses: %s", err)
return fmt.Errorf("failure to parse config.P2P.ListenAddresses: %w", err)
}
}
return h.Network().Listen(maListen...)
Expand All @@ -30,7 +30,7 @@ func addrsFactory(announce, noAnnounce []string) func() (_ p2pconfig.AddrsFactor
for i, addr := range announce {
maAnnounce[i], err = ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("failure to parse config.P2P.AnnounceAddresses: %s", err)
return nil, fmt.Errorf("failure to parse config.P2P.AnnounceAddresses: %w", err)
}
}

Expand All @@ -40,7 +40,7 @@ func addrsFactory(announce, noAnnounce []string) func() (_ p2pconfig.AddrsFactor
for _, addr := range noAnnounce {
maddr, err := ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("failure to parse config.P2P.NoAnnounceAddresses: %s", err)
return nil, fmt.Errorf("failure to parse config.P2P.NoAnnounceAddresses: %w", err)
}
maNoAnnounce[string(maddr.Bytes())] = true
}
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/p2p/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (cfg *Config) mutualPeers() (_ []peer.AddrInfo, err error) {
for i, addr := range cfg.MutualPeers {
maddrs[i], err = ma.NewMultiaddr(addr)
if err != nil {
return nil, fmt.Errorf("failure to parse config.P2P.MutualPeers: %s", err)
return nil, fmt.Errorf("failure to parse config.P2P.MutualPeers: %w", err)
}
}

Expand Down
Loading

0 comments on commit b241223

Please sign in to comment.