grapherrors.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. /*
  11. Package util contains utility classes for the graph storage.
  12. GraphError
  13. Models a graph related error. Low-level errors should be wrapped in a GraphError
  14. before they are returned to a client.
  15. IndexManager
  16. Manages the full text search index. The index supports simple word searches as
  17. well as phrase searches.
  18. The index is a basically a key-value lookup which manages 2 types of entries:
  19. Each node attribute value is split up into words. Each word gets an entry:
  20. PrefixAttrWord + attr num + word (string) -> ids + pos
  21. (provides word and phrase lookup)
  22. Each node attribute value is also converted into a MD5 sum which makes attribute
  23. value lookups very efficient:
  24. PrefixAttrHash + attr num + hash (md5) -> ids
  25. (provides exact match lookup)
  26. NamesManager
  27. Manages names of kinds, roles and attributes. Each stored name gets either a 16
  28. or 32 bit (little endian) number assigned. The manager provides functions to lookup
  29. either the names or their numbers.
  30. */
  31. package util
  32. import (
  33. "errors"
  34. "fmt"
  35. )
  36. /*
  37. GraphError is a graph related error
  38. */
  39. type GraphError struct {
  40. Type error // Error type (to be used for equal checks)
  41. Detail string // Details of this error
  42. }
  43. /*
  44. Error returns a human-readable string representation of this error.
  45. */
  46. func (ge *GraphError) Error() string {
  47. if ge.Detail != "" {
  48. return fmt.Sprintf("GraphError: %v (%v)", ge.Type, ge.Detail)
  49. }
  50. return fmt.Sprintf("GraphError: %v", ge.Type)
  51. }
  52. /*
  53. Graph storage related error types
  54. */
  55. var (
  56. ErrOpening = errors.New("Failed to open graph storage")
  57. ErrFlushing = errors.New("Failed to flush changes")
  58. ErrRollback = errors.New("Failed to rollback changes")
  59. ErrClosing = errors.New("Failed to close graph storage")
  60. ErrAccessComponent = errors.New("Failed to access graph storage component")
  61. ErrReadOnly = errors.New("Failed write to readonly storage")
  62. )
  63. /*
  64. Graph related error types
  65. */
  66. var (
  67. ErrInvalidData = errors.New("Invalid data")
  68. ErrIndexError = errors.New("Index error")
  69. ErrReading = errors.New("Could not read graph information")
  70. ErrWriting = errors.New("Could not write graph information")
  71. ErrRule = errors.New("Graph rule error")
  72. )