Skip to content

Commit dc1c861

Browse files
authored
fix: use errors instead of fmt (#918)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent fcc4364 commit dc1c861

File tree

40 files changed

+155
-202
lines changed

40 files changed

+155
-202
lines changed

cbor/decode.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cbor
1616

1717
import (
1818
"bytes"
19+
"errors"
1920
"fmt"
2021
"math"
2122
"reflect"
@@ -53,7 +54,7 @@ func DecodeIdFromList(cborData []byte) (int, error) {
5354
return 0, err
5455
}
5556
if listLen == 0 {
56-
return 0, fmt.Errorf("cannot return first item from empty list")
57+
return 0, errors.New("cannot return first item from empty list")
5758
}
5859
if listLen < int(CborMaxUintSimple) {
5960
if cborData[1] <= CborMaxUintSimple {
@@ -70,7 +71,7 @@ func DecodeIdFromList(cborData []byte) (int, error) {
7071
// The upstream CBOR library uses uint64 by default for numeric values
7172
case uint64:
7273
if v > uint64(math.MaxInt) {
73-
return 0, fmt.Errorf("decoded numeric value too large: uint64 > int")
74+
return 0, errors.New("decoded numeric value too large: uint64 > int")
7475
}
7576
return int(v), nil
7677
default:
@@ -133,7 +134,7 @@ func DecodeGeneric(cborData []byte, dest interface{}) error {
133134
// destination object
134135
if valueDest.Kind() != reflect.Pointer ||
135136
valueDest.Elem().Kind() != reflect.Struct {
136-
return fmt.Errorf("destination must be a pointer to a struct")
137+
return errors.New("destination must be a pointer to a struct")
137138
}
138139
destTypeFields := []reflect.StructField{}
139140
for i := 0; i < typeDest.NumField(); i++ {

cbor/encode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@ package cbor
1616

1717
import (
1818
"bytes"
19-
"fmt"
19+
"errors"
2020
"reflect"
2121
"sync"
2222

@@ -58,7 +58,7 @@ func EncodeGeneric(src interface{}) ([]byte, error) {
5858
// source object
5959
if valueSrc.Kind() != reflect.Pointer ||
6060
valueSrc.Elem().Kind() != reflect.Struct {
61-
return nil, fmt.Errorf("source must be a pointer to a struct")
61+
return nil, errors.New("source must be a pointer to a struct")
6262
}
6363
srcTypeFields := []reflect.StructField{}
6464
for i := 0; i < typeSrc.NumField(); i++ {

cbor/tags.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package cbor
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
"math/big"
2021
"reflect"
@@ -132,15 +133,15 @@ func (r *Rat) MarshalCBOR() ([]byte, error) {
132133
} else if r.Num().IsInt64() {
133134
tmpContent[0] = r.Num().Int64()
134135
} else {
135-
return nil, fmt.Errorf("numerator cannot be represented at int64/uint64")
136+
return nil, errors.New("numerator cannot be represented at int64/uint64")
136137
}
137138
// Denominator
138139
if r.Denom().IsUint64() {
139140
tmpContent[1] = r.Denom().Uint64()
140141
} else if r.Denom().IsInt64() {
141142
tmpContent[1] = r.Denom().Int64()
142143
} else {
143-
return nil, fmt.Errorf("numerator cannot be represented at int64/uint64")
144+
return nil, errors.New("numerator cannot be represented at int64/uint64")
144145
}
145146
tmpData := _cbor.Tag{
146147
Number: CborTagRational,

cmd/gouroboros/chainsync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616

1717
import (
1818
"encoding/hex"
19+
"errors"
1920
"flag"
2021
"fmt"
2122
"os"
@@ -266,7 +267,7 @@ func chainSyncRollForwardHandler(
266267
blockHash, _ := hex.DecodeString(v.Hash())
267268
var err error
268269
if oConn == nil {
269-
return fmt.Errorf("empty ouroboros connection, aborting!")
270+
return errors.New("empty ouroboros connection, aborting!")
270271
}
271272
block, err = oConn.BlockFetch().Client.GetBlock(common.NewPoint(blockSlot, blockHash))
272273
if err != nil {
@@ -293,7 +294,7 @@ func chainSyncRollForwardHandler(
293294
)
294295
default:
295296
if block == nil {
296-
return fmt.Errorf("block is nil")
297+
return errors.New("block is nil")
297298
}
298299
fmt.Printf(
299300
"era = %s, slot = %d, block_no = %d, id = %s\n",

cmd/gouroboros/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package main
1616

1717
import (
18+
"errors"
1819
"flag"
1920
"fmt"
2021
"net"
@@ -55,7 +56,7 @@ func createListenerSocket(f *globalFlags) (net.Listener, error) {
5556
return nil, fmt.Errorf("failed to open listening socket: %w", err)
5657
}
5758
default:
58-
return nil, fmt.Errorf("no listening address or socket specified")
59+
return nil, errors.New("no listening address or socket specified")
5960
}
6061

6162
return listen, nil

connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -158,7 +158,7 @@ func (c *Connection) DialTimeout(
158158
timeout time.Duration,
159159
) error {
160160
if c.conn != nil {
161-
return fmt.Errorf("a connection was already established")
161+
return errors.New("a connection was already established")
162162
}
163163
conn, err := net.DialTimeout(proto, address, timeout)
164164
if err != nil {

ledger/allegra/rules.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package allegra
1616

1717
import (
18-
"fmt"
18+
"errors"
1919

2020
"github.com/blinklabs-io/gouroboros/ledger/common"
2121
"github.com/blinklabs-io/gouroboros/ledger/shelley"
@@ -68,7 +68,7 @@ func UtxoValidateFeeTooSmallUtxo(
6868
) error {
6969
tmpPparams, ok := pp.(*AllegraProtocolParameters)
7070
if !ok {
71-
return fmt.Errorf("pparams are not expected type")
71+
return errors.New("pparams are not expected type")
7272
}
7373
return shelley.UtxoValidateFeeTooSmallUtxo(
7474
tx,
@@ -113,7 +113,7 @@ func UtxoValidateValueNotConservedUtxo(
113113
) error {
114114
tmpPparams, ok := pp.(*AllegraProtocolParameters)
115115
if !ok {
116-
return fmt.Errorf("pparams are not expected type")
116+
return errors.New("pparams are not expected type")
117117
}
118118
return shelley.UtxoValidateValueNotConservedUtxo(
119119
tx,
@@ -131,7 +131,7 @@ func UtxoValidateOutputTooSmallUtxo(
131131
) error {
132132
tmpPparams, ok := pp.(*AllegraProtocolParameters)
133133
if !ok {
134-
return fmt.Errorf("pparams are not expected type")
134+
return errors.New("pparams are not expected type")
135135
}
136136
return shelley.UtxoValidateOutputTooSmallUtxo(
137137
tx,
@@ -158,7 +158,7 @@ func UtxoValidateMaxTxSizeUtxo(
158158
) error {
159159
tmpPparams, ok := pp.(*AllegraProtocolParameters)
160160
if !ok {
161-
return fmt.Errorf("pparams are not expected type")
161+
return errors.New("pparams are not expected type")
162162
}
163163
return shelley.UtxoValidateMaxTxSizeUtxo(
164164
tx,

ledger/babbage/babbage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package babbage
1717
import (
1818
"encoding/hex"
1919
"encoding/json"
20+
"errors"
2021
"fmt"
2122

2223
"github.com/blinklabs-io/gouroboros/cbor"
@@ -355,7 +356,7 @@ func (d *BabbageTransactionOutputDatumOption) MarshalCBOR() ([]byte, error) {
355356
} else if d.data != nil {
356357
tmpObj = []interface{}{DatumOptionTypeData, cbor.Tag{Number: 24, Content: d.data.Cbor()}}
357358
} else {
358-
return nil, fmt.Errorf("unknown datum option type")
359+
return nil, errors.New("unknown datum option type")
359360
}
360361
return cbor.Encode(&tmpObj)
361362
}

ledger/block.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
package ledger
1616

1717
import (
18+
"errors"
1819
"fmt"
1920

2021
"github.com/blinklabs-io/gouroboros/ledger/common"
@@ -86,5 +87,5 @@ func DetermineBlockType(data []byte) (uint, error) {
8687
if _, err := NewConwayBlockFromCbor(data); err == nil {
8788
return BlockTypeConway, nil
8889
}
89-
return 0, fmt.Errorf("unknown block type")
90+
return 0, errors.New("unknown block type")
9091
}

ledger/byron/byron.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package byron
1616

1717
import (
1818
"encoding/hex"
19+
"errors"
1920
"fmt"
2021
"math"
2122

@@ -342,7 +343,7 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error {
342343
}
343344
default:
344345
// [u8 .ne 0, encoded-cbor]
345-
return fmt.Errorf("can't parse yet")
346+
return errors.New("can't parse yet")
346347
}
347348
return nil
348349
}

0 commit comments

Comments
 (0)