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

fix: use errors, strconv, and concatenation to avoid fmt #436

Merged
merged 1 commit into from
Feb 28, 2025
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
5 changes: 1 addition & 4 deletions cmd/dingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ func main() {
}
// Run node
logger.Info(
fmt.Sprintf(
"version: %s",
version.GetVersionString(),
),
"version: "+version.GetVersionString(),
"component", programName,
)
if err := node.Run(logger); err != nil {
Expand Down
11 changes: 5 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package dingo

import (
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (n *Node) configValidate() error {
)
}
if len(n.config.listeners) == 0 {
return fmt.Errorf("no listeners defined")
return errors.New("no listeners defined")
}
for _, listener := range n.config.listeners {
if listener.Listener != nil {
Expand All @@ -81,14 +82,12 @@ func (n *Node) configValidate() error {
if listener.ListenNetwork != "" && listener.ListenAddress != "" {
continue
}
return fmt.Errorf(
"listener must provide net.Listener or listen network/address values",
)
return errors.New("listener must provide net.Listener or listen network/address values")
}
if n.config.cardanoNodeConfig != nil {
shelleyGenesis := n.config.cardanoNodeConfig.ShelleyGenesis()
if shelleyGenesis == nil {
return fmt.Errorf("unable to get Shelley genesis information")
return errors.New("unable to get Shelley genesis information")
}
if n.config.networkMagic != shelleyGenesis.NetworkMagic {
return fmt.Errorf(
Expand Down
10 changes: 2 additions & 8 deletions connmanager/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ func (c *ConnectionManager) startListener(l ListenerConfig) error {
l.Listener = listener
if l.UseNtC {
c.config.Logger.Info(
fmt.Sprintf(
"listening for ouroboros node-to-node connections on %s",
l.ListenAddress,
),
"listening for ouroboros node-to-node connections on " + l.ListenAddress,
)
} else {
c.config.Logger.Info(
fmt.Sprintf(
"listening for ouroboros node-to-client connections on %s",
l.ListenAddress,
),
"listening for ouroboros node-to-client connections on " + l.ListenAddress,
)
}
}
Expand Down
14 changes: 4 additions & 10 deletions connmanager/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func (c *ConnectionManager) CreateOutboundConn(
dialer.Control = socketControl
}
c.config.Logger.Debug(
fmt.Sprintf(
"establishing TCP connection to: %s",
address,
),
"establishing TCP connection to: "+address,
"role", "client",
)
tmpConn, err := dialer.Dial("tcp", address)
Expand All @@ -73,10 +70,7 @@ func (c *ConnectionManager) CreateOutboundConn(
)
// Setup Ouroboros connection
c.config.Logger.Debug(
fmt.Sprintf(
"establishing ouroboros protocol to %s",
address,
),
"establishing ouroboros protocol to "+address,
"role", "client",
)
oConn, err := ouroboros.NewConnection(
Expand All @@ -86,11 +80,11 @@ func (c *ConnectionManager) CreateOutboundConn(
return nil, err
}
c.config.Logger.Info(
fmt.Sprintf("connected ouroboros to %s", address),
"connected ouroboros to "+address,
"role", "client",
)
c.config.Logger.Debug(
fmt.Sprintf("peer address mapping: address: %s", address),
"peer address mapping: address: "+address,
"role", "client",
"connection_id", oConn.Id().String(),
)
Expand Down
7 changes: 4 additions & 3 deletions database/immutable/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package immutable

import (
"errors"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (c *chunk) Next() (*Block, error) {
}
if c.nextEntry == nil {
if c.currentEntry.BlockOffset > math.MaxInt64 {
return nil, fmt.Errorf("current block offset integer overflow")
return nil, errors.New("current block offset integer overflow")
}
// This triggers even though we check it above
// #nosec G115
Expand Down Expand Up @@ -118,14 +119,14 @@ func (c *chunk) Next() (*Block, error) {
} else {
// Calculate block size based on the offsets for the current and next entries
if c.currentEntry.BlockOffset > math.MaxInt64 {
return nil, fmt.Errorf("current block offset integer overflow")
return nil, errors.New("current block offset integer overflow")
}
// This triggers even though we check it above
// #nosec G115
currOffset := int64(c.currentEntry.BlockOffset)

if c.nextEntry.BlockOffset > math.MaxInt64 {
return nil, fmt.Errorf("next block offset integer overflow")
return nil, errors.New("next block offset integer overflow")
}
// This triggers even though we check it above
// #nosec G115
Expand Down
5 changes: 1 addition & 4 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ func Run(logger *slog.Logger) error {
// Metrics and debug listener
http.Handle("/metrics", promhttp.Handler())
logger.Info(
fmt.Sprintf(
"serving prometheus metrics on %s",
fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.MetricsPort),
),
"serving prometheus metrics on "+fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.MetricsPort),
"component", "node",
)
go func() {
Expand Down
9 changes: 5 additions & 4 deletions peergov/peergov.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ import (
"io"
"log/slog"
"net"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -94,7 +95,7 @@ func (p *PeerGovernor) LoadTopologyConfig(
&Peer{
Address: net.JoinHostPort(
bootstrapPeer.Address,
fmt.Sprintf("%d", bootstrapPeer.Port),
strconv.FormatUint(uint64(bootstrapPeer.Port), 10),
),
Source: PeerSourceTopologyBootstrapPeer,
},
Expand All @@ -108,7 +109,7 @@ func (p *PeerGovernor) LoadTopologyConfig(
&Peer{
Address: net.JoinHostPort(
ap.Address,
fmt.Sprintf("%d", ap.Port),
strconv.FormatUint(uint64(ap.Port), 10),
),
Source: PeerSourceTopologyLocalRoot,
Sharable: localRoot.Advertise,
Expand All @@ -124,7 +125,7 @@ func (p *PeerGovernor) LoadTopologyConfig(
&Peer{
Address: net.JoinHostPort(
ap.Address,
fmt.Sprintf("%d", ap.Port),
strconv.FormatUint(uint64(ap.Port), 10),
),
Source: PeerSourceTopologyPublicRoot,
Sharable: publicRoot.Advertise,
Expand Down
5 changes: 2 additions & 3 deletions peersharing.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
package dingo

import (
"fmt"
"net"
"strconv"

Expand Down Expand Up @@ -58,7 +57,7 @@ func (n *Node) peersharingShareRequest(
continue
}
n.config.logger.Debug(
fmt.Sprintf("adding peer for sharing: %s", peer.Address),
"adding peer for sharing: " + peer.Address,
)
peers = append(peers, opeersharing.PeerAddress{
IP: net.ParseIP(host),
Expand Down
5 changes: 3 additions & 2 deletions state/chainsync.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package state

import (
"encoding/hex"
"errors"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -339,7 +340,7 @@ func (ls *LedgerState) calculateEpochNonce(
byronGenesis := ls.config.CardanoNodeConfig.ByronGenesis()
shelleyGenesis := ls.config.CardanoNodeConfig.ShelleyGenesis()
if byronGenesis == nil || shelleyGenesis == nil {
return nil, fmt.Errorf("could not get genesis config")
return nil, errors.New("could not get genesis config")
}
stabilityWindow := new(big.Rat).Quo(
big.NewRat(
Expand Down
5 changes: 3 additions & 2 deletions state/eras/allegra.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package eras

import (
"encoding/hex"
"errors"
"fmt"

"github.com/blinklabs-io/dingo/config/cardano"
Expand Down Expand Up @@ -101,7 +102,7 @@ func CalculateEtaVAllegra(
}
h, ok := block.Header().(*allegra.AllegraBlockHeader)
if !ok {
return nil, fmt.Errorf("unexpected block type")
return nil, errors.New("unexpected block type")
}
tmpNonce, err := lcommon.CalculateRollingNonce(
prevBlockNonce,
Expand Down
5 changes: 3 additions & 2 deletions state/eras/alonzo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package eras

import (
"encoding/hex"
"errors"
"fmt"

"github.com/blinklabs-io/dingo/config/cardano"
Expand Down Expand Up @@ -103,7 +104,7 @@ func CalculateEtaVAlonzo(
}
h, ok := block.Header().(*alonzo.AlonzoBlockHeader)
if !ok {
return nil, fmt.Errorf("unexpected block type")
return nil, errors.New("unexpected block type")
}
tmpNonce, err := lcommon.CalculateRollingNonce(
prevBlockNonce,
Expand Down
5 changes: 3 additions & 2 deletions state/eras/babbage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package eras

import (
"encoding/hex"
"errors"
"fmt"

"github.com/blinklabs-io/dingo/config/cardano"
Expand Down Expand Up @@ -101,7 +102,7 @@ func CalculateEtaVBabbage(
}
h, ok := block.Header().(*babbage.BabbageBlockHeader)
if !ok {
return nil, fmt.Errorf("unexpected block type")
return nil, errors.New("unexpected block type")
}
tmpNonce, err := lcommon.CalculateRollingNonce(
prevBlockNonce,
Expand Down
4 changes: 2 additions & 2 deletions state/eras/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package eras

import (
"fmt"
"errors"

"github.com/blinklabs-io/dingo/config/cardano"
"github.com/blinklabs-io/gouroboros/ledger/byron"
Expand All @@ -32,7 +32,7 @@ func EpochLengthByron(
) (uint, uint, error) {
byronGenesis := nodeConfig.ByronGenesis()
if byronGenesis == nil {
return 0, 0, fmt.Errorf("unable to get byron genesis")
return 0, 0, errors.New("unable to get byron genesis")
}
// These are known to be within uint range
// #nosec G115
Expand Down
5 changes: 3 additions & 2 deletions state/eras/conway.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package eras

import (
"encoding/hex"
"errors"
"fmt"

"github.com/blinklabs-io/dingo/config/cardano"
Expand Down Expand Up @@ -103,7 +104,7 @@ func CalculateEtaVConway(
}
h, ok := block.Header().(*conway.ConwayBlockHeader)
if !ok {
return nil, fmt.Errorf("unexpected block type")
return nil, errors.New("unexpected block type")
}
tmpNonce, err := lcommon.CalculateRollingNonce(
prevBlockNonce,
Expand Down
5 changes: 3 additions & 2 deletions state/eras/mary.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package eras

import (
"encoding/hex"
"errors"
"fmt"

"github.com/blinklabs-io/dingo/config/cardano"
Expand Down Expand Up @@ -101,7 +102,7 @@ func CalculateEtaVMary(
}
h, ok := block.Header().(*mary.MaryBlockHeader)
if !ok {
return nil, fmt.Errorf("unexpected block type")
return nil, errors.New("unexpected block type")
}
tmpNonce, err := lcommon.CalculateRollingNonce(
prevBlockNonce,
Expand Down
Loading