Skip to content

Commit fcc4364

Browse files
authored
fix: use %w for errors (#917)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 3f0cbcb commit fcc4364

File tree

22 files changed

+52
-52
lines changed

22 files changed

+52
-52
lines changed

cmd/gouroboros/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ func createListenerSocket(f *globalFlags) (net.Listener, error) {
4343
switch {
4444
case f.socket != "":
4545
if err := os.Remove(f.socket); err != nil {
46-
return nil, fmt.Errorf("failed to remove existing socket: %s", err)
46+
return nil, fmt.Errorf("failed to remove existing socket: %w", err)
4747
}
4848
listen, err = net.Listen("unix", f.socket)
4949
if err != nil {
50-
return nil, fmt.Errorf("failed to open listening socket: %s", err)
50+
return nil, fmt.Errorf("failed to open listening socket: %w", err)
5151
}
5252
case f.address != "":
5353
listen, err = net.Listen("tcp", f.address)
5454
if err != nil {
55-
return nil, fmt.Errorf("failed to open listening socket: %s", err)
55+
return nil, fmt.Errorf("failed to open listening socket: %w", err)
5656
}
5757
default:
5858
return nil, fmt.Errorf("no listening address or socket specified")

connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (c *Connection) setupConnection() error {
282282
c.errorChan <- io.EOF
283283
} else {
284284
// Wrap error message to denote it comes from the muxer
285-
c.errorChan <- fmt.Errorf("muxer error: %s", err)
285+
c.errorChan <- fmt.Errorf("muxer error: %w", err)
286286
}
287287
// Close connection on muxer errors
288288
c.Close()
@@ -368,7 +368,7 @@ func (c *Connection) setupConnection() error {
368368
if !ok {
369369
return
370370
}
371-
c.errorChan <- fmt.Errorf("protocol error: %s", err)
371+
c.errorChan <- fmt.Errorf("protocol error: %w", err)
372372
// Close connection on mini-protocol errors
373373
c.Close()
374374
}

ledger/allegra/allegra.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (t *AllegraTransaction) Cbor() []byte {
324324
func NewAllegraBlockFromCbor(data []byte) (*AllegraBlock, error) {
325325
var allegraBlock AllegraBlock
326326
if _, err := cbor.Decode(data, &allegraBlock); err != nil {
327-
return nil, fmt.Errorf("Allegra block decode error: %s", err)
327+
return nil, fmt.Errorf("Allegra block decode error: %w", err)
328328
}
329329
return &allegraBlock, nil
330330
}
@@ -334,15 +334,15 @@ func NewAllegraTransactionBodyFromCbor(
334334
) (*AllegraTransactionBody, error) {
335335
var allegraTx AllegraTransactionBody
336336
if _, err := cbor.Decode(data, &allegraTx); err != nil {
337-
return nil, fmt.Errorf("Allegra transaction body decode error: %s", err)
337+
return nil, fmt.Errorf("Allegra transaction body decode error: %w", err)
338338
}
339339
return &allegraTx, nil
340340
}
341341

342342
func NewAllegraTransactionFromCbor(data []byte) (*AllegraTransaction, error) {
343343
var allegraTx AllegraTransaction
344344
if _, err := cbor.Decode(data, &allegraTx); err != nil {
345-
return nil, fmt.Errorf("Allegra transaction decode error: %s", err)
345+
return nil, fmt.Errorf("Allegra transaction decode error: %w", err)
346346
}
347347
return &allegraTx, nil
348348
}

ledger/alonzo/alonzo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func (t *AlonzoTransaction) Utxorpc() *utxorpc.Tx {
527527
func NewAlonzoBlockFromCbor(data []byte) (*AlonzoBlock, error) {
528528
var alonzoBlock AlonzoBlock
529529
if _, err := cbor.Decode(data, &alonzoBlock); err != nil {
530-
return nil, fmt.Errorf("Alonzo block decode error: %s", err)
530+
return nil, fmt.Errorf("Alonzo block decode error: %w", err)
531531
}
532532
return &alonzoBlock, nil
533533
}
@@ -537,15 +537,15 @@ func NewAlonzoTransactionBodyFromCbor(
537537
) (*AlonzoTransactionBody, error) {
538538
var alonzoTx AlonzoTransactionBody
539539
if _, err := cbor.Decode(data, &alonzoTx); err != nil {
540-
return nil, fmt.Errorf("Alonzo transaction body decode error: %s", err)
540+
return nil, fmt.Errorf("Alonzo transaction body decode error: %w", err)
541541
}
542542
return &alonzoTx, nil
543543
}
544544

545545
func NewAlonzoTransactionFromCbor(data []byte) (*AlonzoTransaction, error) {
546546
var alonzoTx AlonzoTransaction
547547
if _, err := cbor.Decode(data, &alonzoTx); err != nil {
548-
return nil, fmt.Errorf("Alonzo transaction decode error: %s", err)
548+
return nil, fmt.Errorf("Alonzo transaction decode error: %w", err)
549549
}
550550
return &alonzoTx, nil
551551
}
@@ -556,7 +556,7 @@ func NewAlonzoTransactionOutputFromCbor(
556556
var alonzoTxOutput AlonzoTransactionOutput
557557
if _, err := cbor.Decode(data, &alonzoTxOutput); err != nil {
558558
return nil, fmt.Errorf(
559-
"Alonzo transaction output decode error: %s",
559+
"Alonzo transaction output decode error: %w",
560560
err,
561561
)
562562
}

ledger/babbage/babbage.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,15 @@ func (t *BabbageTransaction) Utxorpc() *utxorpc.Tx {
681681
func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) {
682682
var babbageBlock BabbageBlock
683683
if _, err := cbor.Decode(data, &babbageBlock); err != nil {
684-
return nil, fmt.Errorf("Babbage block decode error: %s", err)
684+
return nil, fmt.Errorf("Babbage block decode error: %w", err)
685685
}
686686
return &babbageBlock, nil
687687
}
688688

689689
func NewBabbageBlockHeaderFromCbor(data []byte) (*BabbageBlockHeader, error) {
690690
var babbageBlockHeader BabbageBlockHeader
691691
if _, err := cbor.Decode(data, &babbageBlockHeader); err != nil {
692-
return nil, fmt.Errorf("Babbage block header decode error: %s", err)
692+
return nil, fmt.Errorf("Babbage block header decode error: %w", err)
693693
}
694694
return &babbageBlockHeader, nil
695695
}
@@ -699,15 +699,15 @@ func NewBabbageTransactionBodyFromCbor(
699699
) (*BabbageTransactionBody, error) {
700700
var babbageTx BabbageTransactionBody
701701
if _, err := cbor.Decode(data, &babbageTx); err != nil {
702-
return nil, fmt.Errorf("Babbage transaction body decode error: %s", err)
702+
return nil, fmt.Errorf("Babbage transaction body decode error: %w", err)
703703
}
704704
return &babbageTx, nil
705705
}
706706

707707
func NewBabbageTransactionFromCbor(data []byte) (*BabbageTransaction, error) {
708708
var babbageTx BabbageTransaction
709709
if _, err := cbor.Decode(data, &babbageTx); err != nil {
710-
return nil, fmt.Errorf("Babbage transaction decode error: %s", err)
710+
return nil, fmt.Errorf("Babbage transaction decode error: %w", err)
711711
}
712712
return &babbageTx, nil
713713
}
@@ -718,7 +718,7 @@ func NewBabbageTransactionOutputFromCbor(
718718
var babbageTxOutput BabbageTransactionOutput
719719
if _, err := cbor.Decode(data, &babbageTxOutput); err != nil {
720720
return nil, fmt.Errorf(
721-
"Babbage transaction output decode error: %s",
721+
"Babbage transaction output decode error: %w",
722722
err,
723723
)
724724
}

ledger/byron/byron.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func NewByronEpochBoundaryBlockFromCbor(
689689
) (*ByronEpochBoundaryBlock, error) {
690690
var byronEbbBlock ByronEpochBoundaryBlock
691691
if _, err := cbor.Decode(data, &byronEbbBlock); err != nil {
692-
return nil, fmt.Errorf("Byron EBB block decode error: %s", err)
692+
return nil, fmt.Errorf("Byron EBB block decode error: %w", err)
693693
}
694694
return &byronEbbBlock, nil
695695
}
@@ -699,15 +699,15 @@ func NewByronEpochBoundaryBlockHeaderFromCbor(
699699
) (*ByronEpochBoundaryBlockHeader, error) {
700700
var byronEbbBlockHeader ByronEpochBoundaryBlockHeader
701701
if _, err := cbor.Decode(data, &byronEbbBlockHeader); err != nil {
702-
return nil, fmt.Errorf("Byron EBB block header decode error: %s", err)
702+
return nil, fmt.Errorf("Byron EBB block header decode error: %w", err)
703703
}
704704
return &byronEbbBlockHeader, nil
705705
}
706706

707707
func NewByronMainBlockFromCbor(data []byte) (*ByronMainBlock, error) {
708708
var byronMainBlock ByronMainBlock
709709
if _, err := cbor.Decode(data, &byronMainBlock); err != nil {
710-
return nil, fmt.Errorf("Byron main block decode error: %s", err)
710+
return nil, fmt.Errorf("Byron main block decode error: %w", err)
711711
}
712712
return &byronMainBlock, nil
713713
}
@@ -717,15 +717,15 @@ func NewByronMainBlockHeaderFromCbor(
717717
) (*ByronMainBlockHeader, error) {
718718
var byronMainBlockHeader ByronMainBlockHeader
719719
if _, err := cbor.Decode(data, &byronMainBlockHeader); err != nil {
720-
return nil, fmt.Errorf("Byron main block header decode error: %s", err)
720+
return nil, fmt.Errorf("Byron main block header decode error: %w", err)
721721
}
722722
return &byronMainBlockHeader, nil
723723
}
724724

725725
func NewByronTransactionFromCbor(data []byte) (*ByronTransaction, error) {
726726
var byronTx ByronTransaction
727727
if _, err := cbor.Decode(data, &byronTx); err != nil {
728-
return nil, fmt.Errorf("Byron transaction decode error: %s", err)
728+
return nil, fmt.Errorf("Byron transaction decode error: %w", err)
729729
}
730730
return &byronTx, nil
731731
}

ledger/conway/conway.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,15 @@ func (t *ConwayTransaction) Utxorpc() *utxorpc.Tx {
472472
func NewConwayBlockFromCbor(data []byte) (*ConwayBlock, error) {
473473
var conwayBlock ConwayBlock
474474
if _, err := cbor.Decode(data, &conwayBlock); err != nil {
475-
return nil, fmt.Errorf("Conway block decode error: %s", err)
475+
return nil, fmt.Errorf("Conway block decode error: %w", err)
476476
}
477477
return &conwayBlock, nil
478478
}
479479

480480
func NewConwayBlockHeaderFromCbor(data []byte) (*ConwayBlockHeader, error) {
481481
var conwayBlockHeader ConwayBlockHeader
482482
if _, err := cbor.Decode(data, &conwayBlockHeader); err != nil {
483-
return nil, fmt.Errorf("Conway block header decode error: %s", err)
483+
return nil, fmt.Errorf("Conway block header decode error: %w", err)
484484
}
485485
return &conwayBlockHeader, nil
486486
}
@@ -490,15 +490,15 @@ func NewConwayTransactionBodyFromCbor(
490490
) (*ConwayTransactionBody, error) {
491491
var conwayTx ConwayTransactionBody
492492
if _, err := cbor.Decode(data, &conwayTx); err != nil {
493-
return nil, fmt.Errorf("Conway transaction body decode error: %s", err)
493+
return nil, fmt.Errorf("Conway transaction body decode error: %w", err)
494494
}
495495
return &conwayTx, nil
496496
}
497497

498498
func NewConwayTransactionFromCbor(data []byte) (*ConwayTransaction, error) {
499499
var conwayTx ConwayTransaction
500500
if _, err := cbor.Decode(data, &conwayTx); err != nil {
501-
return nil, fmt.Errorf("Conway transaction decode error: %s", err)
501+
return nil, fmt.Errorf("Conway transaction decode error: %w", err)
502502
}
503503
return &conwayTx, nil
504504
}

ledger/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (e *UtxoFailure) UnmarshalCBOR(data []byte) error {
287287
if err != nil {
288288
newErr, err = NewGenericErrorFromCbor(tmpData.Err)
289289
if err != nil {
290-
return fmt.Errorf("failed to parse UtxoFailure: %s", err)
290+
return fmt.Errorf("failed to parse UtxoFailure: %w", err)
291291
}
292292
}
293293
e.Err = newErr.(error)

ledger/mary/mary.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,23 @@ func (v *MaryTransactionOutputValue) MarshalCBOR() ([]byte, error) {
409409
func NewMaryBlockFromCbor(data []byte) (*MaryBlock, error) {
410410
var maryBlock MaryBlock
411411
if _, err := cbor.Decode(data, &maryBlock); err != nil {
412-
return nil, fmt.Errorf("Mary block decode error: %s", err)
412+
return nil, fmt.Errorf("Mary block decode error: %w", err)
413413
}
414414
return &maryBlock, nil
415415
}
416416

417417
func NewMaryTransactionBodyFromCbor(data []byte) (*MaryTransactionBody, error) {
418418
var maryTx MaryTransactionBody
419419
if _, err := cbor.Decode(data, &maryTx); err != nil {
420-
return nil, fmt.Errorf("Mary transaction body decode error: %s", err)
420+
return nil, fmt.Errorf("Mary transaction body decode error: %w", err)
421421
}
422422
return &maryTx, nil
423423
}
424424

425425
func NewMaryTransactionFromCbor(data []byte) (*MaryTransaction, error) {
426426
var maryTx MaryTransaction
427427
if _, err := cbor.Decode(data, &maryTx); err != nil {
428-
return nil, fmt.Errorf("Mary transaction decode error: %s", err)
428+
return nil, fmt.Errorf("Mary transaction decode error: %w", err)
429429
}
430430
return &maryTx, nil
431431
}
@@ -435,7 +435,7 @@ func NewMaryTransactionOutputFromCbor(
435435
) (*MaryTransactionOutput, error) {
436436
var maryTxOutput MaryTransactionOutput
437437
if _, err := cbor.Decode(data, &maryTxOutput); err != nil {
438-
return nil, fmt.Errorf("Mary transaction output decode error: %s", err)
438+
return nil, fmt.Errorf("Mary transaction output decode error: %w", err)
439439
}
440440
return &maryTxOutput, nil
441441
}

ledger/shelley/shelley.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,15 @@ func (t *ShelleyTransaction) Cbor() []byte {
680680
func NewShelleyBlockFromCbor(data []byte) (*ShelleyBlock, error) {
681681
var shelleyBlock ShelleyBlock
682682
if _, err := cbor.Decode(data, &shelleyBlock); err != nil {
683-
return nil, fmt.Errorf("Shelley block decode error: %s", err)
683+
return nil, fmt.Errorf("Shelley block decode error: %w", err)
684684
}
685685
return &shelleyBlock, nil
686686
}
687687

688688
func NewShelleyBlockHeaderFromCbor(data []byte) (*ShelleyBlockHeader, error) {
689689
var shelleyBlockHeader ShelleyBlockHeader
690690
if _, err := cbor.Decode(data, &shelleyBlockHeader); err != nil {
691-
return nil, fmt.Errorf("Shelley block header decode error: %s", err)
691+
return nil, fmt.Errorf("Shelley block header decode error: %w", err)
692692
}
693693
return &shelleyBlockHeader, nil
694694
}
@@ -698,15 +698,15 @@ func NewShelleyTransactionBodyFromCbor(
698698
) (*ShelleyTransactionBody, error) {
699699
var shelleyTx ShelleyTransactionBody
700700
if _, err := cbor.Decode(data, &shelleyTx); err != nil {
701-
return nil, fmt.Errorf("Shelley transaction body decode error: %s", err)
701+
return nil, fmt.Errorf("Shelley transaction body decode error: %w", err)
702702
}
703703
return &shelleyTx, nil
704704
}
705705

706706
func NewShelleyTransactionFromCbor(data []byte) (*ShelleyTransaction, error) {
707707
var shelleyTx ShelleyTransaction
708708
if _, err := cbor.Decode(data, &shelleyTx); err != nil {
709-
return nil, fmt.Errorf("Shelley transaction decode error: %s", err)
709+
return nil, fmt.Errorf("Shelley transaction decode error: %w", err)
710710
}
711711
return &shelleyTx, nil
712712
}
@@ -717,7 +717,7 @@ func NewShelleyTransactionOutputFromCbor(
717717
var shelleyTxOutput ShelleyTransactionOutput
718718
if _, err := cbor.Decode(data, &shelleyTxOutput); err != nil {
719719
return nil, fmt.Errorf(
720-
"Shelley transaction output decode error: %s",
720+
"Shelley transaction output decode error: %w",
721721
err,
722722
)
723723
}

0 commit comments

Comments
 (0)