github.com/amazechain/amc@v0.1.3/internal/network/error.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package network 18 19 import ( 20 "errors" 21 ) 22 23 var ( 24 badMsgTypeError = errors.New("p2p: message type is invalid") 25 badLengthEncodingError = errors.New("p2p: remaining length field exceeded maximum of 4 bytes") 26 badReturnCodeError = errors.New("p2p: is invalid") 27 dataExceedsPacketError = errors.New("p2p: data exceeds packet length") 28 msgTooLongError = errors.New("p2p: message is too long") 29 packageMsgError = errors.New("p2p: package message error") 30 notFoundPeer = errors.New("p2p: not found peer info") 31 ) 32 33 type panicErr struct { 34 err error 35 } 36 37 func (p panicErr) Error() string { 38 return p.err.Error() 39 } 40 41 func raiseError(err error) { 42 panic(panicErr{err}) 43 } 44 45 func recoverError(existingErr error, recovered interface{}) error { 46 if recovered != nil { 47 if pErr, ok := recovered.(panicErr); ok { 48 return pErr.err 49 } else { 50 panic(recovered) 51 } 52 } 53 return existingErr 54 }