graph: export NewErrf and ErrorCode for upcoming gossiper unit tests
This commit is contained in:
4 files changed
+29
-29
No files matched your search
+14
-14
@@ -2,14 +2,14 @@ package graph
|
||||
|
||||
import "github.com/go-errors/errors"
|
||||
|
||||
// errorCode is used to represent the various errors that can occur within this
|
||||
// ErrorCode is used to represent the various errors that can occur within this
|
||||
// package.
|
||||
type errorCode uint8
|
||||
type ErrorCode uint8
|
||||
|
||||
const (
|
||||
// ErrOutdated is returned when the routing update already have
|
||||
// been applied, or a newer update is already known.
|
||||
ErrOutdated errorCode = iota
|
||||
ErrOutdated ErrorCode = iota
|
||||
|
||||
// ErrIgnored is returned when the update have been ignored because
|
||||
// this update can't bring us something new, or because a node
|
||||
@@ -39,27 +39,27 @@ const (
|
||||
ErrParentValidationFailed
|
||||
)
|
||||
|
||||
// graphError is a structure that represent the error inside the graph package,
|
||||
// Error is a structure that represent the error inside the graph package,
|
||||
// this structure carries additional information about error code in order to
|
||||
// be able distinguish errors outside of the current package.
|
||||
type graphError struct {
|
||||
type Error struct {
|
||||
err *errors.Error
|
||||
code errorCode
|
||||
code ErrorCode
|
||||
}
|
||||
|
||||
// Error represents errors as the string
|
||||
// NOTE: Part of the error interface.
|
||||
func (e *graphError) Error() string {
|
||||
func (e *Error) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// A compile time check to ensure graphError implements the error interface.
|
||||
var _ error = (*graphError)(nil)
|
||||
// A compile time check to ensure Error implements the error interface.
|
||||
var _ error = (*Error)(nil)
|
||||
|
||||
// newErrf creates a graphError by the given error formatted description and
|
||||
// NewErrf creates a Error by the given error formatted description and
|
||||
// its corresponding error code.
|
||||
func newErrf(code errorCode, format string, a ...interface{}) *graphError {
|
||||
return &graphError{
|
||||
func NewErrf(code ErrorCode, format string, a ...interface{}) *Error {
|
||||
return &Error{
|
||||
code: code,
|
||||
err: errors.Errorf(format, a...),
|
||||
}
|
||||
@@ -67,8 +67,8 @@ func newErrf(code errorCode, format string, a ...interface{}) *graphError {
|
||||
|
||||
// IsError is a helper function which is needed to have ability to check that
|
||||
// returned error has specific error code.
|
||||
func IsError(e interface{}, codes ...errorCode) bool {
|
||||
err, ok := e.(*graphError)
|
||||
func IsError(e interface{}, codes ...ErrorCode) bool {
|
||||
err, ok := e.(*Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user