github.com/core-coin/go-core/v2@v2.1.9/p2p/dnsdisc/error.go (about) 1 // Copyright 2019 by the Authors 2 // This file is part of the go-core library. 3 // 4 // The go-core 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 go-core 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 go-core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package dnsdisc 18 19 import ( 20 "errors" 21 "fmt" 22 ) 23 24 // Entry parse errors. 25 var ( 26 errUnknownEntry = errors.New("unknown entry type") 27 errNoPubkey = errors.New("missing public key") 28 errBadPubkey = errors.New("invalid public key") 29 errInvalidENR = errors.New("invalid node record") 30 errInvalidChild = errors.New("invalid child hash") 31 errInvalidSig = errors.New("invalid base64 signature") 32 errSyntax = errors.New("invalid syntax") 33 ) 34 35 // Resolver/sync errors 36 var ( 37 errNoRoot = errors.New("no valid root found") 38 errNoEntry = errors.New("no valid tree entry found") 39 errHashMismatch = errors.New("hash mismatch") 40 errENRInLinkTree = errors.New("enr entry in link tree") 41 errLinkInENRTree = errors.New("link entry in ENR tree") 42 ) 43 44 type nameError struct { 45 name string 46 err error 47 } 48 49 func (err nameError) Error() string { 50 if ee, ok := err.err.(entryError); ok { 51 return fmt.Sprintf("invalid %s entry at %s: %v", ee.typ, err.name, ee.err) 52 } 53 return err.name + ": " + err.err.Error() 54 } 55 56 type entryError struct { 57 typ string 58 err error 59 } 60 61 func (err entryError) Error() string { 62 return fmt.Sprintf("invalid %s entry: %v", err.typ, err.err) 63 }