orion-server icon indicating copy to clipboard operation
orion-server copied to clipboard

Method should never return explicit error type (only `error` interface)

Open liran-funaro opened this issue 2 years ago • 0 comments

Assigning explicit error type (e.g., *ierrors.NotLeaderError) to an interface variable (e.g. var err error) will result in nil check to return false even if we assign a nil to it. See https://go.dev/doc/faq#nil_error and https://go.dev/play/p/8HUKlSDPvCT

The following needs to change in bcdb/db.go:

DB

type DB interface {
	IsLeader() *ierrors.NotLeaderError
}

should be

type DB interface {
	IsLeader() error
}

TxProcessor

type TxProcessor interface {
	IsLeader() *ierrors.NotLeaderError
}

should be

type TxProcessor interface {
	IsLeader() error
}

liran-funaro avatar Nov 24 '22 13:11 liran-funaro