1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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. "
692
702
# TODO: Probably this behavior of should be a common superclass
693
703
class NotBranchError(PathError):
695
_fmt = 'Not a branch: "%(path)s".'
705
_fmt = 'Not a branch: "%(path)s"%(detail)s.'
697
def __init__(self, path):
707
def __init__(self, path, detail=None, bzrdir=None):
698
708
import bzrlib.urlutils as urlutils
699
self.path = urlutils.unescape_for_display(path, 'ascii')
709
path = urlutils.unescape_for_display(path, 'ascii')
710
if detail is not None:
711
detail = ': ' + detail
714
PathError.__init__(self, path=path)
717
# XXX: Ideally self.detail would be a property, but Exceptions in
718
# Python 2.4 have to be old-style classes so properties don't work.
719
# Instead we override _format.
720
if self.detail is None:
721
if self.bzrdir is not None:
723
self.bzrdir.open_repository()
724
except NoRepositoryPresent:
727
self.detail = ': location is a repository'
730
return PathError._format(self)
702
733
class NoSubmitBranch(PathError):
752
783
_fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
785
# use PathNotChild instead
786
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
754
787
def __init__(self, branch, path):
755
788
BzrError.__init__(self)
756
789
self.branch = branch
785
818
class IncompatibleRepositories(BzrError):
819
"""Report an error that two repositories are not compatible.
821
Note that the source and target repositories are permitted to be strings:
822
this exception is thrown from the smart server and may refer to a
823
repository the client hasn't opened.
787
826
_fmt = "%(target)s\n" \
788
827
"is not compatible with\n" \
910
949
# original exception is available as e.original_error
912
951
# New code should prefer to raise specific subclasses
913
def __init__(self, message):
914
# Python 2.5 uses a slot for StandardError.message,
915
# so use a different variable name. We now work around this in
916
# BzrError.__str__, but this member name is kept for compatability.
952
def __init__(self, msg):
920
956
class LockActive(LockError):
1038
1072
self.target = target
1075
class LockCorrupt(LockError):
1077
_fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
1078
"Use 'bzr break-lock' to clear it")
1080
internal_error = False
1082
def __init__(self, corruption_info, file_data=None):
1083
self.corruption_info = corruption_info
1084
self.file_data = file_data
1041
1087
class LockNotHeld(LockError):
1043
1089
_fmt = "Lock not held: %(lock)s"
1143
1189
class InvalidRevisionSpec(BzrError):
1145
_fmt = ("Requested revision: %(spec)r does not exist in branch:"
1146
" %(branch)s%(extra)s")
1191
_fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
1192
" %(branch_url)s%(extra)s")
1148
1194
def __init__(self, spec, branch, extra=None):
1149
1195
BzrError.__init__(self, branch=branch, spec=spec)
1196
self.branch_url = getattr(branch, 'user_url', str(branch))
1151
1198
self.extra = '\n' + str(extra)
1231
1278
class AmbiguousBase(BzrError):
1233
1280
def __init__(self, bases):
1234
warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1281
symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1282
"as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1236
1283
msg = ("The correct base is unclear, because %s are all equally close"
1237
1284
% ", ".join(bases))
1238
1285
BzrError.__init__(self, msg)
1260
1307
class BoundBranchOutOfDate(BzrError):
1262
1309
_fmt = ("Bound branch %(branch)s is out of date with master branch"
1310
" %(master)s.%(extra_help)s")
1265
1312
def __init__(self, branch, master):
1266
1313
BzrError.__init__(self)
1267
1314
self.branch = branch
1268
1315
self.master = master
1316
self.extra_help = ''
1271
1319
class CommitToDoubleBoundBranch(BzrError):
1343
1391
class WeaveParentMismatch(WeaveError):
1345
_fmt = "Parents are mismatched between two revisions. %(message)s"
1393
_fmt = "Parents are mismatched between two revisions. %(msg)s"
1348
1396
class WeaveInvalidChecksum(WeaveError):
1350
_fmt = "Text did not match it's checksum: %(message)s"
1398
_fmt = "Text did not match its checksum: %(msg)s"
1353
1401
class WeaveTextDiffers(WeaveError):
1887
1935
_fmt = "Moving the root directory is not supported at this time"
1938
class TransformRenameFailed(BzrError):
1940
_fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1942
def __init__(self, from_path, to_path, why, errno):
1943
self.from_path = from_path
1944
self.to_path = to_path
1890
1949
class BzrMoveFailedError(BzrError):
1892
1951
_fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1937
1996
"Use --keep to not delete them, or --force to delete them regardless.")
1939
1998
def __init__(self, tree_delta):
1999
symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
2000
"BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
1940
2001
BzrError.__init__(self)
1941
2002
self.changes_as_text = tree_delta.get_changes_as_text()
1942
2003
#self.paths_as_string = '\n'.join(changed_files)
1997
2058
class BadConversionTarget(BzrError):
1999
_fmt = "Cannot convert to format %(format)s. %(problem)s"
2060
_fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2001
def __init__(self, problem, format):
2063
def __init__(self, problem, format, from_format=None):
2002
2064
BzrError.__init__(self)
2003
2065
self.problem = problem
2004
2066
self.format = format
2067
self.from_format = from_format or '(unspecified)'
2007
2070
class NoDiffFound(BzrError):
2084
2147
class OutOfDateTree(BzrError):
2086
_fmt = "Working tree is out of date, please run 'bzr update'."
2149
_fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2088
def __init__(self, tree):
2151
def __init__(self, tree, more=None):
2089
2156
BzrError.__init__(self)
2090
2157
self.tree = tree
2093
2161
class PublicBranchOutOfDate(BzrError):
2132
2200
def __init__(self, repo):
2133
2201
BzrError.__init__(self)
2134
self.repo_path = repo.bzrdir.root_transport.base
2202
self.repo_path = repo.user_url
2137
2205
class InconsistentDelta(BzrError):
2147
2215
self.reason = reason
2218
class InconsistentDeltaDelta(InconsistentDelta):
2219
"""Used when we get a delta that is not valid."""
2221
_fmt = ("An inconsistent delta was supplied: %(delta)r"
2222
"\nreason: %(reason)s")
2224
def __init__(self, delta, reason):
2225
BzrError.__init__(self)
2227
self.reason = reason
2150
2230
class UpgradeRequired(BzrError):
2152
2232
_fmt = "To use this feature you must upgrade your branch at %(path)s."
2698
2778
def __init__(self, bzrdir):
2699
2779
import bzrlib.urlutils as urlutils
2700
display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2780
display_url = urlutils.unescape_for_display(bzrdir.user_url,
2702
2782
BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2769
2849
class UncommittedChanges(BzrError):
2771
_fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2851
_fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2852
' (See bzr status).%(more)s')
2773
def __init__(self, tree):
2854
def __init__(self, tree, more=None):
2774
2859
import bzrlib.urlutils as urlutils
2775
display_url = urlutils.unescape_for_display(
2776
tree.bzrdir.root_transport.base, 'ascii')
2777
BzrError.__init__(self, tree=tree, display_url=display_url)
2860
user_url = getattr(tree, "user_url", None)
2861
if user_url is None:
2862
display_url = str(tree)
2864
display_url = urlutils.unescape_for_display(user_url, 'ascii')
2865
BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2868
class ShelvedChanges(UncommittedChanges):
2870
_fmt = ('Working tree "%(display_url)s" has shelved changes'
2871
' (See bzr shelve --list).%(more)s')
2780
2874
class MissingTemplateVariable(BzrError):
2886
2980
_fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2888
2982
def __init__(self, host, port, orig_error):
2983
# nb: in python2.4 socket.error doesn't have a useful repr
2889
2984
BzrError.__init__(self, host=host, port=port,
2890
orig_error=orig_error[1])
2985
orig_error=repr(orig_error.args))
2893
2988
class UnknownRules(BzrError):
2901
2996
class HookFailed(BzrError):
2902
2997
"""Raised when a pre_change_branch_tip hook function fails anything other
2903
2998
than TipChangeRejected.
3000
Note that this exception is no longer raised, and the import is only left
3001
to be nice to code which might catch it in a plugin.
2906
3004
_fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2907
3005
"%(traceback_text)s%(exc_value)s")
2909
def __init__(self, hook_stage, hook_name, exc_info):
3007
def __init__(self, hook_stage, hook_name, exc_info, warn=True):
3009
symbol_versioning.warn("BzrError HookFailed has been deprecated "
3010
"as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2910
3011
import traceback
2911
3012
self.hook_stage = hook_stage
2912
3013
self.hook_name = hook_name
3034
3135
def __init__(self, source_branch, target_branch):
3035
3136
self.source_branch = source_branch
3036
3137
self.target_branch = target_branch
3140
class NoRoundtrippingSupport(BzrError):
3142
_fmt = ("Roundtripping is not supported between %(source_branch)r and "
3143
"%(target_branch)r.")
3145
internal_error = True
3147
def __init__(self, source_branch, target_branch):
3148
self.source_branch = source_branch
3149
self.target_branch = target_branch
3152
class FileTimestampUnavailable(BzrError):
3154
_fmt = "The filestamp for %(path)s is not available."
3156
internal_error = True
3158
def __init__(self, path):
3162
class NoColocatedBranchSupport(BzrError):
3164
_fmt = ("%(bzrdir)r does not support co-located branches.")
3166
def __init__(self, bzrdir):
3167
self.bzrdir = bzrdir
3170
class NoWhoami(BzrError):
3172
_fmt = ('Unable to determine your name.\n'
3173
"Please, set your name with the 'whoami' command.\n"
3174
'E.g. bzr whoami "Your Name <name@example.com>"')
3177
class InvalidPattern(BzrError):
3179
_fmt = ('Invalid pattern(s) found. %(msg)s')
3181
def __init__(self, msg):
3185
class RecursiveBind(BzrError):
3187
_fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3188
'Please use `bzr unbind` to fix.')
3190
def __init__(self, branch_url):
3191
self.branch_url = branch_url