Skip to content

Commit

Permalink
go: Use errors.Join introduced in go 1.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Aug 24, 2023
1 parent 07a576e commit a9e32a0
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 67 deletions.
4 changes: 2 additions & 2 deletions go/common/logging/zap_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package logging

import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"go.uber.org/multierr"
"go.uber.org/zap/zapcore"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ func (t turduckens) MarshalLogArray(enc zapcore.ArrayEncoder) error {
var err error
tur := turducken{}
for i := 0; i < int(t); i++ {
err = multierr.Append(err, enc.AppendObject(tur))
err = errors.Join(err, enc.AppendObject(tur))
}
return err
}
Expand Down
5 changes: 2 additions & 3 deletions go/consensus/cometbft/abci/messages.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package abci

import (
"errors"
"fmt"

"github.com/hashicorp/go-multierror"

"github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api"
)

Expand Down Expand Up @@ -33,7 +32,7 @@ func (md *messageDispatcher) Publish(ctx *api.Context, kind, msg interface{}) (i
var errs error
for _, ms := range md.subscriptions[kind] {
if resp, err := ms.ExecuteMessage(ctx, kind, msg); err != nil {
errs = multierror.Append(errs, err)
errs = errors.Join(errs, err)
} else {
switch {
case resp != nil && result == nil:
Expand Down
12 changes: 6 additions & 6 deletions go/consensus/cometbft/governance/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package governance

import (
"context"
"errors"
"fmt"

cmtabcitypes "github.com/cometbft/cometbft/abci/types"
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/hashicorp/go-multierror"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
Expand Down Expand Up @@ -215,7 +215,7 @@ func EventsFromCometBFT(
// Proposal submitted event.
var e api.ProposalSubmittedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("governance: corrupt ProposalSubmitted event: %w", err))
errs = errors.Join(errs, fmt.Errorf("governance: corrupt ProposalSubmitted event: %w", err))
continue
}

Expand All @@ -225,7 +225,7 @@ func EventsFromCometBFT(
// Proposal executed event.
var e api.ProposalExecutedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("governance: corrupt ProposalExecuted event: %w", err))
errs = errors.Join(errs, fmt.Errorf("governance: corrupt ProposalExecuted event: %w", err))
continue
}

Expand All @@ -235,7 +235,7 @@ func EventsFromCometBFT(
// Proposal finalized event.
var e api.ProposalFinalizedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("governance: corrupt ProposalFinalized event: %w", err))
errs = errors.Join(errs, fmt.Errorf("governance: corrupt ProposalFinalized event: %w", err))
continue
}

Expand All @@ -245,14 +245,14 @@ func EventsFromCometBFT(
// Vote event.
var e api.VoteEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("governance: corrupt Vote event: %w", err))
errs = errors.Join(errs, fmt.Errorf("governance: corrupt Vote event: %w", err))
continue
}

evt := &api.Event{Height: height, TxHash: txHash, Vote: &e}
events = append(events, evt)
default:
errs = multierror.Append(errs, fmt.Errorf("governance: unknown event type: key: %s, val: %s", key, val))
errs = errors.Join(errs, fmt.Errorf("governance: unknown event type: key: %s, val: %s", key, val))
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions go/consensus/cometbft/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package registry

import (
"context"
"errors"
"fmt"

cmtabcitypes "github.com/cometbft/cometbft/abci/types"
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/eapache/channels"
"github.com/hashicorp/go-multierror"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/entity"
Expand Down Expand Up @@ -314,7 +314,7 @@ func EventsFromCometBFT(
// Runtime started event.
var e api.RuntimeStartedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("registry: corrupt RuntimeStarted event: %w", err))
errs = errors.Join(errs, fmt.Errorf("registry: corrupt RuntimeStarted event: %w", err))
continue
}

Expand All @@ -323,7 +323,7 @@ func EventsFromCometBFT(
// Runtime suspended event.
var e api.RuntimeSuspendedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("registry: corrupt RuntimeSuspended event: %w", err))
errs = errors.Join(errs, fmt.Errorf("registry: corrupt RuntimeSuspended event: %w", err))
continue
}

Expand All @@ -332,7 +332,7 @@ func EventsFromCometBFT(
// Entity event.
var e api.EntityEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("registry: corrupt Entity event: %w", err))
errs = errors.Join(errs, fmt.Errorf("registry: corrupt Entity event: %w", err))
continue
}

Expand All @@ -341,7 +341,7 @@ func EventsFromCometBFT(
// Node event.
var e api.NodeEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("registry: corrupt Node event: %w", err))
errs = errors.Join(errs, fmt.Errorf("registry: corrupt Node event: %w", err))
continue
}

Expand All @@ -350,7 +350,7 @@ func EventsFromCometBFT(
// Node unfrozen event.
var e api.NodeUnfrozenEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("registry: corrupt NodeUnfrozen event: %w", err))
errs = errors.Join(errs, fmt.Errorf("registry: corrupt NodeUnfrozen event: %w", err))
continue
}
events = append(events, &api.Event{Height: height, TxHash: txHash, NodeUnfrozenEvent: &e})
Expand Down
18 changes: 9 additions & 9 deletions go/consensus/cometbft/roothash/roothash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package roothash

import (
"context"
"errors"
"fmt"
"math"
"sync"
Expand All @@ -12,7 +13,6 @@ import (
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/eapache/channels"
"github.com/hashicorp/go-multierror"

"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/crash"
Expand Down Expand Up @@ -757,7 +757,7 @@ EventLoop:
// Finalized event.
var e api.FinalizedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: corrupt Finalized event: %w", err))
errs = errors.Join(errs, fmt.Errorf("roothash: corrupt Finalized event: %w", err))
continue EventLoop
}

Expand All @@ -766,7 +766,7 @@ EventLoop:
// An execution discrepancy has been detected.
var e api.ExecutionDiscrepancyDetectedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: corrupt ExecutionDiscrepancyDetected event: %w", err))
errs = errors.Join(errs, fmt.Errorf("roothash: corrupt ExecutionDiscrepancyDetected event: %w", err))
continue EventLoop
}

Expand All @@ -775,7 +775,7 @@ EventLoop:
// An executor commit has been processed.
var e api.ExecutorCommittedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: corrupt ExecutorComitted event: %w", err))
errs = errors.Join(errs, fmt.Errorf("roothash: corrupt ExecutorComitted event: %w", err))
continue EventLoop
}

Expand All @@ -784,29 +784,29 @@ EventLoop:
// Incoming message processed event.
var e api.InMsgProcessedEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: corrupt InMsgProcessed event: %w", err))
errs = errors.Join(errs, fmt.Errorf("roothash: corrupt InMsgProcessed event: %w", err))
continue EventLoop
}

ev = &api.Event{InMsgProcessed: &e}
case eventsAPI.IsAttributeKind(key, &api.RuntimeIDAttribute{}):
if runtimeID != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: duplicate runtime ID attribute"))
errs = errors.Join(errs, fmt.Errorf("roothash: duplicate runtime ID attribute"))
continue EventLoop
}
rtAttribute := api.RuntimeIDAttribute{}
if err := eventsAPI.DecodeValue(val, &rtAttribute); err != nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: corrupt runtime ID: %w", err))
errs = errors.Join(errs, fmt.Errorf("roothash: corrupt runtime ID: %w", err))
continue EventLoop
}
runtimeID = &rtAttribute.ID
default:
errs = multierror.Append(errs, fmt.Errorf("roothash: unknown event type: key: %s, val: %s", key, val))
errs = errors.Join(errs, fmt.Errorf("roothash: unknown event type: key: %s, val: %s", key, val))
}
}

if runtimeID == nil {
errs = multierror.Append(errs, fmt.Errorf("roothash: missing runtime ID attribute"))
errs = errors.Join(errs, fmt.Errorf("roothash: missing runtime ID attribute"))
continue
}
if ev != nil {
Expand Down
18 changes: 9 additions & 9 deletions go/consensus/cometbft/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package staking

import (
"context"
"errors"
"fmt"

cmtabcitypes "github.com/cometbft/cometbft/abci/types"
cmtpubsub "github.com/cometbft/cometbft/libs/pubsub"
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/hashicorp/go-multierror"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
Expand Down Expand Up @@ -342,7 +342,7 @@ func EventsFromCometBFT(
// Take escrow event.
var e api.TakeEscrowEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt TakeEscrow event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt TakeEscrow event: %w", err))
continue
}

Expand All @@ -352,7 +352,7 @@ func EventsFromCometBFT(
// Transfer event.
var e api.TransferEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt Transfer event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt Transfer event: %w", err))
continue
}

Expand All @@ -362,7 +362,7 @@ func EventsFromCometBFT(
// Reclaim escrow event.
var e api.ReclaimEscrowEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt ReclaimEscrow event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt ReclaimEscrow event: %w", err))
continue
}

Expand All @@ -372,7 +372,7 @@ func EventsFromCometBFT(
// Add escrow event.
var e api.AddEscrowEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt AddEscrow event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt AddEscrow event: %w", err))
continue
}

Expand All @@ -382,7 +382,7 @@ func EventsFromCometBFT(
// Debonding start escrow event.
var e api.DebondingStartEscrowEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt DebondingStart escrow event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt DebondingStart escrow event: %w", err))
continue
}

Expand All @@ -392,7 +392,7 @@ func EventsFromCometBFT(
// Burn event.
var e api.BurnEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt Burn event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt Burn event: %w", err))
continue
}

Expand All @@ -402,14 +402,14 @@ func EventsFromCometBFT(
// Allowance change event.
var e api.AllowanceChangeEvent
if err := eventsAPI.DecodeValue(val, &e); err != nil {
errs = multierror.Append(errs, fmt.Errorf("staking: corrupt AllowanceChange event: %w", err))
errs = errors.Join(errs, fmt.Errorf("staking: corrupt AllowanceChange event: %w", err))
continue
}

evt := &api.Event{Height: height, TxHash: txHash, AllowanceChange: &e}
events = append(events, evt)
default:
errs = multierror.Append(errs, fmt.Errorf("staking: unknown event type: key: %s, val: %s", key, val))
errs = errors.Join(errs, fmt.Errorf("staking: unknown event type: key: %s, val: %s", key, val))
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/golang/snappy v0.0.4
github.com/google/btree v1.1.2
github.com/hashicorp/go-hclog v1.4.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-plugin v1.4.6
github.com/hpcloud/tail v1.0.0
github.com/ipfs/go-log/v2 v2.5.1
Expand All @@ -51,7 +50,6 @@ require (
github.com/thepudds/fzgo v0.2.2
github.com/tidwall/btree v1.6.0
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.25.0
golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0
Expand Down Expand Up @@ -102,7 +100,6 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
Expand Down Expand Up @@ -183,6 +180,7 @@ require (
go.opencensus.io v0.24.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/fx v1.20.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,8 @@ github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is=
github.com/gtank/merlin v0.1.1/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc=
github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-hclog v1.4.0 h1:ctuWFGrhFha8BnnzxqeRGidlEcQkDyL5u8J8t5eA11I=
github.com/hashicorp/go-hclog v1.4.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.4.6 h1:MDV3UrKQBM3du3G7MApDGvOsMYy3JQJ4exhSoKBAeVA=
github.com/hashicorp/go-plugin v1.4.6/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
Loading

0 comments on commit a9e32a0

Please sign in to comment.