Skip to content

Commit

Permalink
reorganize errros (#92)
Browse files Browse the repository at this point in the history
Signed-off-by: sczembor <[email protected]>
  • Loading branch information
sczembor authored Jan 14, 2025
1 parent 6e45cc4 commit 14515c4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
9 changes: 9 additions & 0 deletions bitcoin/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bitcoin

import "errors"

// ErrNoBtcConfig is returned when the btc config is missing.
var ErrNoBtcConfig = errors.New("missing bitcoin node configuration")

// ErrNoNativeProcessor is returned when the btcProcessor is nil.
var ErrNoBtcProcessor = errors.New("btcProcessor cannot be nil")
6 changes: 6 additions & 0 deletions dal/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dal

import "errors"

// ErrNoDB is returned when the database is nil.
var ErrNoDB = errors.New("database cannot be nil")
18 changes: 0 additions & 18 deletions errors/errors.go

This file was deleted.

5 changes: 2 additions & 3 deletions ika2btc/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/errors"
"github.com/rs/zerolog/log"
)

Expand All @@ -29,11 +28,11 @@ func NewProcessor(
) (*Processor, error) {

if db == nil {
return nil, errors.ErrNoDB
return nil, dal.ErrNoDB
}

if btcClientConfig.Host == "" || btcClientConfig.User == "" || btcClientConfig.Pass == "" {
return nil, errors.ErrNoBtcConfig
return nil, bitcoin.ErrNoBtcConfig
}

client, err := rpcclient.New(&btcClientConfig, nil)
Expand Down
5 changes: 2 additions & 3 deletions ika2btc/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/dal/daltest"
"github.com/gonative-cc/relayer/errors"
"gotest.tools/v3/assert"
)

Expand Down Expand Up @@ -43,14 +42,14 @@ func TestCheckConfirmations(t *testing.T) {
func TestNewProcessor(t *testing.T) {
// missing db
processor, err := NewProcessor(btcClientConfig, 6, nil)
assert.ErrorIs(t, err, errors.ErrNoDB)
assert.ErrorIs(t, err, dal.ErrNoDB)
assert.Assert(t, processor == nil)

// missing BTC config
db := daltest.InitTestDB(t)
btcClientConfig.Host = ""
processor, err = NewProcessor(btcClientConfig, 6, db)
assert.ErrorIs(t, err, errors.ErrNoBtcConfig)
assert.ErrorIs(t, err, bitcoin.ErrNoBtcConfig)
assert.Assert(t, processor == nil)
}

Expand Down
9 changes: 9 additions & 0 deletions native/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package native

import "errors"

// ErrNoFetcher is returned when the fetcher is nil.
var ErrNoFetcher = errors.New("sign requests fetcher cannot be nil")

// ErrNoNativeProcessor is returned when the nativeProcessor is nil.
var ErrNoNativeProcessor = errors.New("nativeProcessor cannot be nil")
10 changes: 5 additions & 5 deletions nbtc/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"time"

"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
err "github.com/gonative-cc/relayer/errors"
"github.com/gonative-cc/relayer/ika2btc"
"github.com/gonative-cc/relayer/native"
"github.com/gonative-cc/relayer/native2ika"
Expand Down Expand Up @@ -55,19 +55,19 @@ func NewRelayer(
) (*Relayer, error) {

if db == nil {
return nil, err.ErrNoDB
return nil, dal.ErrNoDB
}

if nativeProcessor == nil {
return nil, err.ErrNoNativeProcessor
return nil, native.ErrNoNativeProcessor
}

if btcProcessor == nil {
return nil, err.ErrNoBtcProcessor
return nil, bitcoin.ErrNoBtcProcessor
}

if fetcher == nil {
return nil, err.ErrNoFetcher
return nil, native.ErrNoFetcher
}

if relayerConfig.ProcessTxsInterval == 0 {
Expand Down
9 changes: 4 additions & 5 deletions nbtc/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/gonative-cc/relayer/bitcoin"
"github.com/gonative-cc/relayer/dal"
"github.com/gonative-cc/relayer/dal/daltest"
err "github.com/gonative-cc/relayer/errors"
"github.com/gonative-cc/relayer/ika"
"github.com/gonative-cc/relayer/ika2btc"
"github.com/gonative-cc/relayer/native"
Expand Down Expand Up @@ -107,31 +106,31 @@ func TestNewRelayer_ErrorCases(t *testing.T) {
db: nil,
nativeProcessor: ts.nativeProcessor,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoDB,
expectedError: dal.ErrNoDB,
fetcher: ts.signReqFetcher,
},
{
name: "NativeProcessorError",
db: ts.db,
nativeProcessor: nil,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoNativeProcessor,
expectedError: native.ErrNoNativeProcessor,
fetcher: ts.signReqFetcher,
},
{
name: "BtcProcessorError",
db: ts.db,
nativeProcessor: ts.nativeProcessor,
btcProcessor: nil,
expectedError: err.ErrNoBtcProcessor,
expectedError: bitcoin.ErrNoBtcProcessor,
fetcher: ts.signReqFetcher,
},
{
name: "BlockchainError",
db: ts.db,
nativeProcessor: ts.nativeProcessor,
btcProcessor: ts.btcProcessor,
expectedError: err.ErrNoFetcher,
expectedError: native.ErrNoFetcher,
fetcher: nil,
},
}
Expand Down

0 comments on commit 14515c4

Please sign in to comment.