aboutsummaryrefslogtreecommitdiffstats
path: root/eth/error.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-02-02 21:22:20 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-02-02 21:22:20 +0800
commit1e60919d47ac2767706c135332a1a4f79bbf3960 (patch)
tree3db2f5d5446f451d700bf67ef756d85da0fdda25 /eth/error.go
parent313cfba7d43529db647789ae826bc426d9da7de3 (diff)
parent0d97c3ce1322083fb9683a5afec004b2626b620a (diff)
downloaddexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar.gz
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar.bz2
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar.lz
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar.xz
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.tar.zst
dexon-1e60919d47ac2767706c135332a1a4f79bbf3960.zip
Merge pull request #3 from ethereum/develop
Update to develop
Diffstat (limited to 'eth/error.go')
-rw-r--r--eth/error.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/eth/error.go b/eth/error.go
new file mode 100644
index 000000000..9c4a68481
--- /dev/null
+++ b/eth/error.go
@@ -0,0 +1,72 @@
+package eth
+
+import (
+ "fmt"
+)
+
+const (
+ ErrMsgTooLarge = iota
+ ErrDecode
+ ErrInvalidMsgCode
+ ErrProtocolVersionMismatch
+ ErrNetworkIdMismatch
+ ErrGenesisBlockMismatch
+ ErrNoStatusMsg
+ ErrExtraStatusMsg
+ ErrInvalidBlock
+ ErrInvalidPoW
+ ErrUnrequestedBlock
+ ErrInsufficientChainInfo
+)
+
+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",
+ ErrInsufficientChainInfo: "Insufficient chain info",
+}
+
+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) {
+ if len(message) == 0 {
+ var ok bool
+ self.message, ok = errorToString[self.Code]
+ if !ok {
+ panic("invalid error code")
+ }
+ if self.format != "" {
+ self.message += ": " + fmt.Sprintf(self.format, self.params...)
+ }
+ }
+ return self.message
+}
+
+func (self *protocolError) Fatal() bool {
+ return self.fatal
+}