13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Exceptions for bzr, and reporting of them.
33
33
# TODO: is there any value in providing the .args field used by standard
34
# python exceptions? A list of values with no names seems less useful
34
# python exceptions? A list of values with no names seems less useful
37
# TODO: Perhaps convert the exception to a string at the moment it's
37
# TODO: Perhaps convert the exception to a string at the moment it's
38
38
# constructed to make sure it will succeed. But that says nothing about
39
39
# exceptions that are never raised.
72
72
arguments can be given. The first is for generic "user" errors which
73
73
are not intended to be caught and so do not need a specific subclass.
74
74
The second case is for use with subclasses that provide a _fmt format
75
string to print the arguments.
75
string to print the arguments.
77
Keyword arguments are taken as parameters to the error, which can
78
be inserted into the format string template. It's recommended
79
that subclasses override the __init__ method to require specific
77
Keyword arguments are taken as parameters to the error, which can
78
be inserted into the format string template. It's recommended
79
that subclasses override the __init__ method to require specific
82
82
:param msg: If given, this is the literal complete text for the error,
477
477
def __init__(self, name, value):
478
478
BzrError.__init__(self, name=name, value=value)
481
481
class StrictCommitFailed(BzrError):
483
483
_fmt = "Commit refused because there are unknown files in the tree"
486
486
# XXX: Should be unified with TransportError; they seem to represent the
488
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
489
# - this is finer than a TransportError - and more useful as such. It
489
# - this is finer than a TransportError - and more useful as such. It
490
490
# differentiates between 'transport has failed' and 'operation on a transport
492
492
class PathError(BzrError):
494
494
_fmt = "Generic path error: %(path)r%(extra)s)"
496
496
def __init__(self, path, extra=None):
639
class UnstackableLocationError(BzrError):
641
_fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
643
def __init__(self, branch_url, target_url):
644
BzrError.__init__(self)
645
self.branch_url = branch_url
646
self.target_url = target_url
639
649
class UnstackableRepositoryFormat(BzrError):
641
651
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
690
700
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
701
# the exception object is a bit undesirable.
692
# TODO: Probably this behavior of should be a common superclass
702
# TODO: Probably this behavior of should be a common superclass
693
703
class NotBranchError(PathError):
695
705
_fmt = 'Not a branch: "%(path)s".'
1004
1014
class LockContention(LockError):
1006
_fmt = 'Could not acquire lock "%(lock)s"'
1016
_fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1007
1017
# TODO: show full url for lock, combining the transport and relative
1010
1020
internal_error = False
1012
def __init__(self, lock):
1022
def __init__(self, lock, msg=''):
1013
1023
self.lock = lock
1016
1027
class LockBroken(LockError):
1131
1142
class NoSuchRevisionInTree(NoSuchRevision):
1132
1143
"""When using Tree.revision_tree, and the revision is not accessible."""
1134
1145
_fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1136
1147
def __init__(self, tree, revision_id):
1172
1183
class DivergedBranches(BzrError):
1174
1185
_fmt = ("These branches have diverged."
1175
" Use the merge command to reconcile them.")
1186
" Use the missing command to see how.\n"
1187
"Use the merge command to reconcile them.")
1177
1189
def __init__(self, branch1, branch2):
1178
1190
self.branch1 = branch1
1226
1238
not_ancestor_id=not_ancestor_id)
1229
class InstallFailed(BzrError):
1231
def __init__(self, revisions):
1232
revision_str = ", ".join(str(r) for r in revisions)
1233
msg = "Could not install revisions:\n%s" % revision_str
1234
BzrError.__init__(self, msg)
1235
self.revisions = revisions
1238
1241
class AmbiguousBase(BzrError):
1240
1243
def __init__(self, bases):
1384
1387
class VersionedFileError(BzrError):
1386
1389
_fmt = "Versioned file error"
1389
1392
class RevisionNotPresent(VersionedFileError):
1391
1394
_fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1393
1396
def __init__(self, revision_id, file_id):
1450
1453
def __init__(self, stream_format, target_format):
1451
1454
self.stream_format = stream_format
1452
1455
self.target_format = target_format
1455
1458
class KnitDataStreamUnknown(KnitError):
1456
1459
# Indicates a data stream we don't know how to handle.
1634
1637
self.port = ':%s' % port
1640
# XXX: This is also used for unexpected end of file, which is different at the
1641
# TCP level from "connection reset".
1637
1642
class ConnectionReset(TransportError):
1639
1644
_fmt = "Connection closed: %(msg)s %(orig_error)s"
1730
1735
class WorkingTreeNotRevision(BzrError):
1732
_fmt = ("The working tree for %(basedir)s has changed since"
1737
_fmt = ("The working tree for %(basedir)s has changed since"
1733
1738
" the last commit, but weave merge requires that it be"
2049
2054
_fmt = """This tree contains left-over files from a failed operation.
2050
2055
Please examine %(limbo_dir)s to see if it contains any files you wish to
2051
2056
keep, and delete it when you are done."""
2053
2058
def __init__(self, limbo_dir):
2054
2059
BzrError.__init__(self)
2055
2060
self.limbo_dir = limbo_dir
2089
2094
class OutOfDateTree(BzrError):
2091
_fmt = "Working tree is out of date, please run 'bzr update'."
2096
_fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2093
def __init__(self, tree):
2098
def __init__(self, tree, more=None):
2094
2103
BzrError.__init__(self)
2095
2104
self.tree = tree
2098
2108
class PublicBranchOutOfDate(BzrError):
2166
2176
_fmt = "To use this feature you must upgrade your repository at %(path)s."
2179
class RichRootUpgradeRequired(UpgradeRequired):
2181
_fmt = ("To use this feature you must upgrade your branch at %(path)s to"
2182
" a format which supports rich roots.")
2169
2185
class LocalRequiresBoundBranch(BzrError):
2171
2187
_fmt = "Cannot perform local-only commits on unbound branches."
2174
class InvalidProgressBarType(BzrError):
2176
_fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2177
" is not a supported type Select one of: %(valid_types)s")
2179
def __init__(self, bar_type, valid_types):
2180
BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2183
2190
class UnsupportedOperation(BzrError):
2185
2192
_fmt = ("The method %(mname)s is not supported on"
2245
2252
self.text = text
2248
class MalformedHeader(BadBundle):
2255
class MalformedHeader(BadBundle):
2250
2257
_fmt = "Malformed bzr revision-bundle header: %(text)r"
2253
class MalformedPatches(BadBundle):
2260
class MalformedPatches(BadBundle):
2255
2262
_fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2258
class MalformedFooter(BadBundle):
2265
class MalformedFooter(BadBundle):
2260
2267
_fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2263
2270
class UnsupportedEOLMarker(BadBundle):
2265
_fmt = "End of line marker was not \\n in bzr revision-bundle"
2272
_fmt = "End of line marker was not \\n in bzr revision-bundle"
2267
2274
def __init__(self):
2268
# XXX: BadBundle's constructor assumes there's explanatory text,
2275
# XXX: BadBundle's constructor assumes there's explanatory text,
2269
2276
# but for this there is not
2270
2277
BzrError.__init__(self)
2273
2280
class IncompatibleBundleFormat(BzrError):
2275
2282
_fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2277
2284
def __init__(self, bundle_format, other):
2306
2313
self.transport = transport
2309
class NoSmartServer(NotBranchError):
2311
_fmt = "No smart server available at %(url)s"
2313
@symbol_versioning.deprecated_method(symbol_versioning.one_four)
2314
def __init__(self, url):
2318
2316
class UnknownSSH(BzrError):
2320
2318
_fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2502
2500
class MalformedBugIdentifier(BzrError):
2504
_fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2502
_fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2503
'See "bzr help bugs" for more information on this feature.')
2506
2505
def __init__(self, bug_id, reason):
2507
2506
self.bug_id = bug_id
2528
2527
self.branch = branch
2530
class InvalidLineInBugsProperty(BzrError):
2532
_fmt = ("Invalid line in bugs property: '%(line)s'")
2534
def __init__(self, line):
2538
class InvalidBugStatus(BzrError):
2540
_fmt = ("Invalid bug status: '%(status)s'")
2542
def __init__(self, status):
2543
self.status = status
2531
2546
class UnexpectedSmartServerResponse(BzrError):
2533
2548
_fmt = "Could not understand response from smart server: %(response_tuple)r"
2588
2603
class UnknownContainerFormatError(ContainerError):
2590
2605
_fmt = "Unrecognised container format: %(container_format)r"
2592
2607
def __init__(self, container_format):
2593
2608
self.container_format = container_format
2769
2784
class UncommittedChanges(BzrError):
2771
_fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2786
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2787
' (See bzr status).%(more)s')
2773
def __init__(self, tree):
2789
def __init__(self, tree, more=None):
2774
2794
import bzrlib.urlutils as urlutils
2775
2795
display_url = urlutils.unescape_for_display(
2776
2796
tree.bzrdir.root_transport.base, 'ascii')
2777
BzrError.__init__(self, tree=tree, display_url=display_url)
2797
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2780
2800
class MissingTemplateVariable(BzrError):
2817
2837
class CommandAvailableInPlugin(StandardError):
2819
2839
internal_error = False
2821
2841
def __init__(self, cmd_name, plugin_metadata, provider):
2823
2843
self.plugin_metadata = plugin_metadata
2824
2844
self.cmd_name = cmd_name
2825
2845
self.provider = provider
2827
2847
def __str__(self):
2829
_fmt = ('"%s" is not a standard bzr command. \n'
2849
_fmt = ('"%s" is not a standard bzr command. \n'
2830
2850
'However, the following official plugin provides this command: %s\n'
2831
2851
'You can install it by going to: %s'
2832
% (self.cmd_name, self.plugin_metadata['name'],
2852
% (self.cmd_name, self.plugin_metadata['name'],
2833
2853
self.plugin_metadata['url']))
2838
2858
class NoPluginAvailable(BzrError):
2842
class NotATerminal(BzrError):
2844
_fmt = 'Unable to ask for a password without real terminal.'
2847
2862
class UnableEncodePath(BzrError):
2954
2969
BzrError.__init__(self, invalid_id=invalid_id)
2972
class JailBreak(BzrError):
2974
_fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2976
def __init__(self, url):
2977
BzrError.__init__(self, url=url)
2957
2980
class UserAbort(BzrError):
2959
2982
_fmt = 'The user aborted the operation.'
2966
2989
def __init__(self, format, url):
2967
2990
BzrError.__init__(self, format=format, url=url)
2993
class NoSuchView(BzrError):
2994
"""A view does not exist.
2997
_fmt = u"No such view: %(view_name)s."
2999
def __init__(self, view_name):
3000
self.view_name = view_name
3003
class ViewsNotSupported(BzrError):
3004
"""Views are not supported by a tree format.
3007
_fmt = ("Views are not supported by %(tree)s;"
3008
" use 'bzr upgrade' to change your tree to a later format.")
3010
def __init__(self, tree):
3014
class FileOutsideView(BzrError):
3016
_fmt = ('Specified file "%(file_name)s" is outside the current view: '
3019
def __init__(self, file_name, view_files):
3020
self.file_name = file_name
3021
self.view_str = ", ".join(view_files)
3024
class UnresumableWriteGroup(BzrError):
3026
_fmt = ("Repository %(repository)s cannot resume write group "
3027
"%(write_groups)r: %(reason)s")
3029
internal_error = True
3031
def __init__(self, repository, write_groups, reason):
3032
self.repository = repository
3033
self.write_groups = write_groups
3034
self.reason = reason
3037
class UnsuspendableWriteGroup(BzrError):
3039
_fmt = ("Repository %(repository)s cannot suspend a write group.")
3041
internal_error = True
3043
def __init__(self, repository):
3044
self.repository = repository
3047
class LossyPushToSameVCS(BzrError):
3049
_fmt = ("Lossy push not possible between %(source_branch)r and "
3050
"%(target_branch)r that are in the same VCS.")
3052
internal_error = True
3054
def __init__(self, source_branch, target_branch):
3055
self.source_branch = source_branch
3056
self.target_branch = target_branch