diff options
author | Viktor TrĂ³n <viktor.tron@gmail.com> | 2018-10-03 20:59:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-03 20:59:41 +0800 |
commit | e5677114dc7461fe39ebe353a4657aa4cb03fde4 (patch) | |
tree | 8605f9a8b726b158fd01b4befced1e3ba92ca1f9 /swarm/storage/feed/error.go | |
parent | 303b99663e963a520aaa44eca68e042d9fe230af (diff) | |
parent | de01178c18766b9f744acc94fe2b96804f998e40 (diff) | |
download | go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.gz go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.bz2 go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.lz go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.xz go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.tar.zst go-tangerine-e5677114dc7461fe39ebe353a4657aa4cb03fde4.zip |
Merge pull request #17796 from epiclabs-io/mru-feeds
swarm/storage/feeds: Renamed MRU to Swarm Feeds
Diffstat (limited to 'swarm/storage/feed/error.go')
-rw-r--r-- | swarm/storage/feed/error.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/swarm/storage/feed/error.go b/swarm/storage/feed/error.go new file mode 100644 index 000000000..206ba3316 --- /dev/null +++ b/swarm/storage/feed/error.go @@ -0,0 +1,73 @@ +// Copyright 2018 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. + +package feed + +import ( + "fmt" +) + +const ( + ErrInit = iota + ErrNotFound + ErrIO + ErrUnauthorized + ErrInvalidValue + ErrDataOverflow + ErrNothingToReturn + ErrCorruptData + ErrInvalidSignature + ErrNotSynced + ErrPeriodDepth + ErrCnt +) + +// Error is a the typed error object used for Swarm feeds +type Error struct { + code int + err string +} + +// Error implements the error interface +func (e *Error) Error() string { + return e.err +} + +// Code returns the error code +// Error codes are enumerated in the error.go file within the feeds package +func (e *Error) Code() int { + return e.code +} + +// NewError creates a new Swarm feeds Error object with the specified code and custom error message +func NewError(code int, s string) error { + if code < 0 || code >= ErrCnt { + panic("no such error code!") + } + r := &Error{ + err: s, + } + switch code { + case ErrNotFound, ErrIO, ErrUnauthorized, ErrInvalidValue, ErrDataOverflow, ErrNothingToReturn, ErrInvalidSignature, ErrNotSynced, ErrPeriodDepth, ErrCorruptData: + r.code = code + } + return r +} + +// NewErrorf is a convenience version of NewError that incorporates printf-style formatting +func NewErrorf(code int, format string, args ...interface{}) error { + return NewError(code, fmt.Sprintf(format, args...)) +} |