PageRenderTime 59ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/mercurial/error.py

https://bitbucket.org/timeless/mercurial-crew
Python | 248 lines | 188 code | 24 blank | 36 comment | 2 complexity | faa950d7e061daad36d93a88e1474778 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. # error.py - Mercurial exceptions
  2. #
  3. # Copyright 2005-2008 Matt Mackall <mpm@selenic.com>
  4. #
  5. # This software may be used and distributed according to the terms of the
  6. # GNU General Public License version 2 or any later version.
  7. """Mercurial exceptions.
  8. This allows us to catch exceptions at higher levels without forcing
  9. imports.
  10. """
  11. from __future__ import absolute_import
  12. # Do not import anything here, please
  13. class Hint(object):
  14. """Mix-in to provide a hint of an error
  15. This should come first in the inheritance list to consume a hint and
  16. pass remaining arguments to the exception class.
  17. """
  18. def __init__(self, *args, **kw):
  19. self.hint = kw.pop('hint', None)
  20. super(Hint, self).__init__(*args, **kw)
  21. class RevlogError(Hint, Exception):
  22. pass
  23. class FilteredIndexError(IndexError):
  24. pass
  25. class LookupError(RevlogError, KeyError):
  26. def __init__(self, name, index, message):
  27. self.name = name
  28. self.index = index
  29. # this can't be called 'message' because at least some installs of
  30. # Python 2.6+ complain about the 'message' property being deprecated
  31. self.lookupmessage = message
  32. if isinstance(name, str) and len(name) == 20:
  33. from .node import short
  34. name = short(name)
  35. RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
  36. def __str__(self):
  37. return RevlogError.__str__(self)
  38. class FilteredLookupError(LookupError):
  39. pass
  40. class ManifestLookupError(LookupError):
  41. pass
  42. class CommandError(Exception):
  43. """Exception raised on errors in parsing the command line."""
  44. class InterventionRequired(Hint, Exception):
  45. """Exception raised when a command requires human intervention."""
  46. class Abort(Hint, Exception):
  47. """Raised if a command needs to print an error and exit."""
  48. class HookLoadError(Abort):
  49. """raised when loading a hook fails, aborting an operation
  50. Exists to allow more specialized catching."""
  51. class HookAbort(Abort):
  52. """raised when a validation hook fails, aborting an operation
  53. Exists to allow more specialized catching."""
  54. class ConfigError(Abort):
  55. """Exception raised when parsing config files"""
  56. class UpdateAbort(Abort):
  57. """Raised when an update is aborted for destination issue"""
  58. class MergeDestAbort(Abort):
  59. """Raised when an update is aborted for destination issues"""
  60. class NoMergeDestAbort(MergeDestAbort):
  61. """Raised when an update is aborted because there is nothing to merge"""
  62. class ManyMergeDestAbort(MergeDestAbort):
  63. """Raised when an update is aborted because destination is ambiguous"""
  64. class ResponseExpected(Abort):
  65. """Raised when an EOF is received for a prompt"""
  66. def __init__(self):
  67. from .i18n import _
  68. Abort.__init__(self, _('response expected'))
  69. class OutOfBandError(Hint, Exception):
  70. """Exception raised when a remote repo reports failure"""
  71. class ParseError(Hint, Exception):
  72. """Raised when parsing config files and {rev,file}sets (msg[, pos])"""
  73. class UnknownIdentifier(ParseError):
  74. """Exception raised when a {rev,file}set references an unknown identifier"""
  75. def __init__(self, function, symbols):
  76. from .i18n import _
  77. ParseError.__init__(self, _("unknown identifier: %s") % function)
  78. self.function = function
  79. self.symbols = symbols
  80. class RepoError(Hint, Exception):
  81. pass
  82. class RepoLookupError(RepoError):
  83. pass
  84. class FilteredRepoLookupError(RepoLookupError):
  85. pass
  86. class CapabilityError(RepoError):
  87. pass
  88. class RequirementError(RepoError):
  89. """Exception raised if .hg/requires has an unknown entry."""
  90. class UnsupportedMergeRecords(Abort):
  91. def __init__(self, recordtypes):
  92. from .i18n import _
  93. self.recordtypes = sorted(recordtypes)
  94. s = ' '.join(self.recordtypes)
  95. Abort.__init__(
  96. self, _('unsupported merge state records: %s') % s,
  97. hint=_('see https://mercurial-scm.org/wiki/MergeStateRecords for '
  98. 'more information'))
  99. class LockError(IOError):
  100. def __init__(self, errno, strerror, filename, desc):
  101. IOError.__init__(self, errno, strerror, filename)
  102. self.desc = desc
  103. class LockHeld(LockError):
  104. def __init__(self, errno, filename, desc, locker):
  105. LockError.__init__(self, errno, 'Lock held', filename, desc)
  106. self.locker = locker
  107. class LockUnavailable(LockError):
  108. pass
  109. # LockError is for errors while acquiring the lock -- this is unrelated
  110. class LockInheritanceContractViolation(RuntimeError):
  111. pass
  112. class ResponseError(Exception):
  113. """Raised to print an error with part of output and exit."""
  114. class UnknownCommand(Exception):
  115. """Exception raised if command is not in the command table."""
  116. class AmbiguousCommand(Exception):
  117. """Exception raised if command shortcut matches more than one command."""
  118. # derived from KeyboardInterrupt to simplify some breakout code
  119. class SignalInterrupt(KeyboardInterrupt):
  120. """Exception raised on SIGTERM and SIGHUP."""
  121. class SignatureError(Exception):
  122. pass
  123. class PushRaced(RuntimeError):
  124. """An exception raised during unbundling that indicate a push race"""
  125. class ProgrammingError(RuntimeError):
  126. """Raised if a mercurial (core or extension) developer made a mistake"""
  127. # bundle2 related errors
  128. class BundleValueError(ValueError):
  129. """error raised when bundle2 cannot be processed"""
  130. class BundleUnknownFeatureError(BundleValueError):
  131. def __init__(self, parttype=None, params=(), values=()):
  132. self.parttype = parttype
  133. self.params = params
  134. self.values = values
  135. if self.parttype is None:
  136. msg = 'Stream Parameter'
  137. else:
  138. msg = parttype
  139. entries = self.params
  140. if self.params and self.values:
  141. assert len(self.params) == len(self.values)
  142. entries = []
  143. for idx, par in enumerate(self.params):
  144. val = self.values[idx]
  145. if val is None:
  146. entries.append(val)
  147. else:
  148. entries.append("%s=%r" % (par, val))
  149. if entries:
  150. msg = '%s - %s' % (msg, ', '.join(entries))
  151. ValueError.__init__(self, msg)
  152. class ReadOnlyPartError(RuntimeError):
  153. """error raised when code tries to alter a part being generated"""
  154. class PushkeyFailed(Abort):
  155. """error raised when a pushkey part failed to update a value"""
  156. def __init__(self, partid, namespace=None, key=None, new=None, old=None,
  157. ret=None):
  158. self.partid = partid
  159. self.namespace = namespace
  160. self.key = key
  161. self.new = new
  162. self.old = old
  163. self.ret = ret
  164. # no i18n expected to be processed into a better message
  165. Abort.__init__(self, 'failed to update value for "%s/%s"'
  166. % (namespace, key))
  167. class CensoredNodeError(RevlogError):
  168. """error raised when content verification fails on a censored node
  169. Also contains the tombstone data substituted for the uncensored data.
  170. """
  171. def __init__(self, filename, node, tombstone):
  172. from .node import short
  173. RevlogError.__init__(self, '%s:%s' % (filename, short(node)))
  174. self.tombstone = tombstone
  175. class CensoredBaseError(RevlogError):
  176. """error raised when a delta is rejected because its base is censored
  177. A delta based on a censored revision must be formed as single patch
  178. operation which replaces the entire base with new content. This ensures
  179. the delta may be applied by clones which have not censored the base.
  180. """
  181. class InvalidBundleSpecification(Exception):
  182. """error raised when a bundle specification is invalid.
  183. This is used for syntax errors as opposed to support errors.
  184. """
  185. class UnsupportedBundleSpecification(Exception):
  186. """error raised when a bundle specification is not supported."""
  187. class CorruptedState(Exception):
  188. """error raised when a command is not able to read its state from file"""