errors.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Copyright 2014 The lldb Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Some errors returned by this package.
  5. //
  6. // Note that this package can return more errors than declared here, for
  7. // example io.EOF from Filer.ReadAt().
  8. package lldb
  9. import (
  10. "fmt"
  11. )
  12. // ErrDecodeScalars is possibly returned from DecodeScalars
  13. type ErrDecodeScalars struct {
  14. B []byte // Data being decoded
  15. I int // offending offset
  16. }
  17. // Error implements the built in error type.
  18. func (e *ErrDecodeScalars) Error() string {
  19. return fmt.Sprintf("DecodeScalars: corrupted data @ %d/%d", e.I, len(e.B))
  20. }
  21. // ErrINVAL reports invalid values passed as parameters, for example negative
  22. // offsets where only non-negative ones are allowed or read from the DB.
  23. type ErrINVAL struct {
  24. Src string
  25. Val interface{}
  26. }
  27. // Error implements the built in error type.
  28. func (e *ErrINVAL) Error() string {
  29. return fmt.Sprintf("%s: %+v", e.Src, e.Val)
  30. }
  31. // ErrPERM is for example reported when a Filer is closed while BeginUpdate(s)
  32. // are not balanced with EndUpdate(s)/Rollback(s) or when EndUpdate or Rollback
  33. // is invoked which is not paired with a BeginUpdate.
  34. type ErrPERM struct {
  35. Src string
  36. }
  37. // Error implements the built in error type.
  38. func (e *ErrPERM) Error() string {
  39. return fmt.Sprintf("%s: Operation not permitted", e.Src)
  40. }
  41. // ErrTag represents an ErrILSEQ kind.
  42. type ErrType int
  43. // ErrILSEQ types
  44. const (
  45. ErrOther ErrType = iota
  46. ErrAdjacentFree // Adjacent free blocks (.Off and .Arg)
  47. ErrDecompress // Used compressed block: corrupted compression
  48. ErrExpFreeTag // Expected a free block tag, got .Arg
  49. ErrExpUsedTag // Expected a used block tag, got .Arg
  50. ErrFLT // Free block is invalid or referenced multiple times
  51. ErrFLTLoad // FLT truncated to .Off, need size >= .Arg
  52. ErrFLTSize // Free block size (.Arg) doesn't belong to its list min size: .Arg2
  53. ErrFileSize // File .Name size (.Arg) != 0 (mod 16)
  54. ErrFreeChaining // Free block, .prev.next doesn't point back to this block
  55. ErrFreeTailBlock // Last block is free
  56. ErrHead // Head of a free block list has non zero Prev (.Arg)
  57. ErrInvalidRelocTarget // Reloc doesn't target (.Arg) a short or long used block
  58. ErrInvalidWAL // Corrupted write ahead log. .Name: file name, .More: more
  59. ErrLongFreeBlkTooLong // Long free block spans beyond EOF, size .Arg
  60. ErrLongFreeBlkTooShort // Long free block must have at least 2 atoms, got only .Arg
  61. ErrLongFreeNextBeyondEOF // Long free block .Next (.Arg) spans beyond EOF
  62. ErrLongFreePrevBeyondEOF // Long free block .Prev (.Arg) spans beyond EOF
  63. ErrLongFreeTailTag // Expected a long free block tail tag, got .Arg
  64. ErrLostFreeBlock // Free block is not in any FLT list
  65. ErrNullReloc // Used reloc block with nil target
  66. ErrRelocBeyondEOF // Used reloc points (.Arg) beyond EOF
  67. ErrShortFreeTailTag // Expected a short free block tail tag, got .Arg
  68. ErrSmall // Request for a free block (.Arg) returned a too small one (.Arg2) at .Off
  69. ErrTailTag // Block at .Off has invalid tail CC (compression code) tag, got .Arg
  70. ErrUnexpReloc // Unexpected reloc block referred to from reloc block .Arg
  71. ErrVerifyPadding // Used block has nonzero padding
  72. ErrVerifyTailSize // Long free block size .Arg but tail size .Arg2
  73. ErrVerifyUsedSpan // Used block size (.Arg) spans beyond EOF
  74. )
  75. // ErrILSEQ reports a corrupted file format. Details in fields according to Type.
  76. type ErrILSEQ struct {
  77. Type ErrType
  78. Off int64
  79. Arg int64
  80. Arg2 int64
  81. Arg3 int64
  82. Name string
  83. More interface{}
  84. }
  85. // Error implements the built in error type.
  86. func (e *ErrILSEQ) Error() string {
  87. switch e.Type {
  88. case ErrAdjacentFree:
  89. return fmt.Sprintf("Adjacent free blocks at offset %#x and %#x", e.Off, e.Arg)
  90. case ErrDecompress:
  91. return fmt.Sprintf("Compressed block at offset %#x: Corrupted compressed content", e.Off)
  92. case ErrExpFreeTag:
  93. return fmt.Sprintf("Block at offset %#x: Expected a free block tag, got %#2x", e.Off, e.Arg)
  94. case ErrExpUsedTag:
  95. return fmt.Sprintf("Block at ofset %#x: Expected a used block tag, got %#2x", e.Off, e.Arg)
  96. case ErrFLT:
  97. return fmt.Sprintf("Free block at offset %#x is invalid or referenced multiple times", e.Off)
  98. case ErrFLTLoad:
  99. return fmt.Sprintf("FLT truncated to size %d, expected at least %d", e.Off, e.Arg)
  100. case ErrFLTSize:
  101. return fmt.Sprintf("Free block at offset %#x has size (%#x) should be at least (%#x)", e.Off, e.Arg, e.Arg2)
  102. case ErrFileSize:
  103. return fmt.Sprintf("File %q size (%#x) != 0 (mod 16)", e.Name, e.Arg)
  104. case ErrFreeChaining:
  105. return fmt.Sprintf("Free block at offset %#x: .prev.next doesn point back here.", e.Off)
  106. case ErrFreeTailBlock:
  107. return fmt.Sprintf("Free block at offset %#x: Cannot be last file block", e.Off)
  108. case ErrHead:
  109. return fmt.Sprintf("Block at offset %#x: Head of free block list has non zero .prev %#x", e.Off, e.Arg)
  110. case ErrInvalidRelocTarget:
  111. return fmt.Sprintf("Used reloc block at offset %#x: Target (%#x) is not a short or long used block", e.Off, e.Arg)
  112. case ErrInvalidWAL:
  113. return fmt.Sprintf("Corrupted write ahead log file: %q %v", e.Name, e.More)
  114. case ErrLongFreeBlkTooLong:
  115. return fmt.Sprintf("Long free block at offset %#x: Size (%#x) beyond EOF", e.Off, e.Arg)
  116. case ErrLongFreeBlkTooShort:
  117. return fmt.Sprintf("Long free block at offset %#x: Size (%#x) too small", e.Off, e.Arg)
  118. case ErrLongFreeNextBeyondEOF:
  119. return fmt.Sprintf("Long free block at offset %#x: Next (%#x) points beyond EOF", e.Off, e.Arg)
  120. case ErrLongFreePrevBeyondEOF:
  121. return fmt.Sprintf("Long free block at offset %#x: Prev (%#x) points beyond EOF", e.Off, e.Arg)
  122. case ErrLongFreeTailTag:
  123. return fmt.Sprintf("Block at offset %#x: Expected long free tail tag, got %#2x", e.Off, e.Arg)
  124. case ErrLostFreeBlock:
  125. return fmt.Sprintf("Free block at offset %#x: not in any FLT list", e.Off)
  126. case ErrNullReloc:
  127. return fmt.Sprintf("Used reloc block at offset %#x: Nil target", e.Off)
  128. case ErrRelocBeyondEOF:
  129. return fmt.Sprintf("Used reloc block at offset %#x: Link (%#x) points beyond EOF", e.Off, e.Arg)
  130. case ErrShortFreeTailTag:
  131. return fmt.Sprintf("Block at offset %#x: Expected short free tail tag, got %#2x", e.Off, e.Arg)
  132. case ErrSmall:
  133. return fmt.Sprintf("Request for of free block of size %d returned a too small (%d) one at offset %#x", e.Arg, e.Arg2, e.Off)
  134. case ErrTailTag:
  135. return fmt.Sprintf("Block at offset %#x: Invalid tail CC tag, got %#2x", e.Off, e.Arg)
  136. case ErrUnexpReloc:
  137. return fmt.Sprintf("Block at offset %#x: Unexpected reloc block. Referred to from reloc block at offset %#x", e.Off, e.Arg)
  138. case ErrVerifyPadding:
  139. return fmt.Sprintf("Used block at offset %#x: Nonzero padding", e.Off)
  140. case ErrVerifyTailSize:
  141. return fmt.Sprintf("Long free block at offset %#x: Size %#x, but tail size %#x", e.Off, e.Arg, e.Arg2)
  142. case ErrVerifyUsedSpan:
  143. return fmt.Sprintf("Used block at offset %#x: Size %#x spans beyond EOF", e.Off, e.Arg)
  144. }
  145. more := ""
  146. if e.More != nil {
  147. more = fmt.Sprintf(", %v", e.More)
  148. }
  149. off := ""
  150. if e.Off != 0 {
  151. off = fmt.Sprintf(", off: %#x", e.Off)
  152. }
  153. return fmt.Sprintf("Error%s%s", off, more)
  154. }