error.go 1.9 KB

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