Skip to content

Method should never return explicit error type (only error interface) #468

@liran-funaro

Description

@liran-funaro

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions