diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-02 17:30:27 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-02 17:30:27 +0800 |
commit | 0fb1bcd32192b8bf05a328b955a08da4cefe0180 (patch) | |
tree | 67460b927eb41b2876e8e6b7eb9dece494dbd088 /eth/error.go | |
parent | 8da07e91e40c1d1bb43763b7e959ae92e5770af2 (diff) | |
parent | a4dc12f12c7a06f5e28d5b1e760249875ef7a8c5 (diff) | |
download | go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.gz go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.bz2 go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.lz go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.xz go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.zst go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.zip |
Merge branch 'poc8' into docbranch
Diffstat (limited to 'eth/error.go')
-rw-r--r-- | eth/error.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/eth/error.go b/eth/error.go new file mode 100644 index 000000000..d1daad575 --- /dev/null +++ b/eth/error.go @@ -0,0 +1,71 @@ +package eth + +import ( + "fmt" +) + +const ( + ErrMsgTooLarge = iota + ErrDecode + ErrInvalidMsgCode + ErrProtocolVersionMismatch + ErrNetworkIdMismatch + ErrGenesisBlockMismatch + ErrNoStatusMsg + ErrExtraStatusMsg + ErrInvalidBlock + ErrInvalidPoW + ErrUnrequestedBlock +) + +var errorToString = map[int]string{ + ErrMsgTooLarge: "Message too long", + ErrDecode: "Invalid message", + ErrInvalidMsgCode: "Invalid message code", + ErrProtocolVersionMismatch: "Protocol version mismatch", + ErrNetworkIdMismatch: "NetworkId mismatch", + ErrGenesisBlockMismatch: "Genesis block mismatch", + ErrNoStatusMsg: "No status message", + ErrExtraStatusMsg: "Extra status message", + ErrInvalidBlock: "Invalid block", + ErrInvalidPoW: "Invalid PoW", + ErrUnrequestedBlock: "Unrequested block", +} + +type protocolError struct { + Code int + fatal bool + message string + format string + params []interface{} + // size int +} + +func newProtocolError(code int, format string, params ...interface{}) *protocolError { + return &protocolError{Code: code, format: format, params: params} +} + +func ProtocolError(code int, format string, params ...interface{}) (err *protocolError) { + err = newProtocolError(code, format, params...) + // report(err) + return +} + +func (self protocolError) Error() (message string) { + message = self.message + if message == "" { + message, ok := errorToString[self.Code] + if !ok { + panic("invalid error code") + } + if self.format != "" { + message += ": " + fmt.Sprintf(self.format, self.params...) + } + self.message = message + } + return +} + +func (self *protocolError) Fatal() bool { + return self.fatal +} |