/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2005, 2006 Canonical Ltd
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
2
#
1 by mbp at sourcefrog
import from baz patch-364
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
7
#
1 by mbp at sourcefrog
import from baz patch-364
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
12
#
1 by mbp at sourcefrog
import from baz patch-364
13
# You should have received a copy of the GNU General Public License
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
16
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
17
"""Exceptions for bzr, and reporting of them.
18
"""
19
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
20
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
21
from bzrlib import (symbol_versioning,
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
22
                    osutils,)
1185.82.128 by Aaron Bentley
Provide errors from bzrlib.patches in bzrlib.errors
23
from bzrlib.patches import (PatchSyntax, 
24
                            PatchConflict, 
25
                            MalformedPatchHeader,
26
                            MalformedHunkHeader,
27
                            MalformedLine,)
28
29
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
30
# TODO: is there any value in providing the .args field used by standard
31
# python exceptions?   A list of values with no names seems less useful 
32
# to me.
33
1185.16.63 by Martin Pool
- more error conversion
34
# TODO: Perhaps convert the exception to a string at the moment it's 
35
# constructed to make sure it will succeed.  But that says nothing about
36
# exceptions that are never raised.
37
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
38
# TODO: selftest assertRaises should probably also check that every error
39
# raised can be formatted as a string successfully, and without giving
40
# 'unprintable'.
1662.1.12 by Martin Pool
Translate unknown sftp errors to PathError, no NoSuchFile
41
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
42
1 by mbp at sourcefrog
import from baz patch-364
43
class BzrError(StandardError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
44
    """
45
    Base class for errors raised by bzrlib.
46
2067.3.2 by Martin Pool
Error cleanup review comments:
47
    :cvar internal_error: if true (or absent) this was probably caused by a
48
    bzr bug and should be displayed with a traceback; if False this was
49
    probably a user or environment error and they don't need the gory details.
50
    (That can be overridden by -Derror on the command line.)
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
51
2067.3.2 by Martin Pool
Error cleanup review comments:
52
    :cvar _fmt: Format string to display the error; this is expanded
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
53
    by the instance's dict.
54
    """
1740.5.6 by Martin Pool
Clean up many exception classes.
55
    
2067.3.2 by Martin Pool
Error cleanup review comments:
56
    internal_error = False
1685.2.1 by Brian M. Carlson
Add a workaround for usage of the args attribute in exceptions.
57
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
58
    def __init__(self, msg=None, **kwds):
59
        """Construct a new BzrError.
60
61
        There are two alternative forms for constructing these objects.
62
        Either a preformatted string may be passed, or a set of named
63
        arguments can be given.  The first is for generic "user" errors which
64
        are not intended to be caught and so do not need a specific subclass.
65
        The second case is for use with subclasses that provide a _fmt format
66
        string to print the arguments.  
67
68
        Keyword arguments are taken as parameters to the error, which can 
69
        be inserted into the format string template.  It's recommended 
70
        that subclasses override the __init__ method to require specific 
71
        parameters.
72
2067.3.2 by Martin Pool
Error cleanup review comments:
73
        :param msg: If given, this is the literal complete text for the error,
74
        not subject to expansion.
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
75
        """
76
        StandardError.__init__(self)
77
        if msg is not None:
2067.3.4 by Martin Pool
Error deprecations will come in for 0.13
78
            # I was going to deprecate this, but it actually turns out to be
79
            # quite handy - mbp 20061103.
2067.3.2 by Martin Pool
Error cleanup review comments:
80
            self._preformatted_string = msg
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
81
        else:
2067.3.2 by Martin Pool
Error cleanup review comments:
82
            self._preformatted_string = None
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
83
            for key, value in kwds.items():
84
                setattr(self, key, value)
85
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
86
    def __str__(self):
2067.3.2 by Martin Pool
Error cleanup review comments:
87
        s = getattr(self, '_preformatted_string', None)
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
88
        if s is not None:
89
            # contains a preformatted message; must be cast to plain str
90
            return str(s)
91
        try:
2067.3.2 by Martin Pool
Error cleanup review comments:
92
            fmt = self._get_format_string()
93
            if fmt:
94
                s = fmt % self.__dict__
95
                # __str__() should always return a 'str' object
96
                # never a 'unicode' object.
97
                if isinstance(s, unicode):
98
                    return s.encode('utf8')
99
                return s
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
100
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
101
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
102
                % (self.__class__.__name__,
103
                   self.__dict__,
104
                   getattr(self, '_fmt', None),
105
                   str(e))
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
106
2067.3.2 by Martin Pool
Error cleanup review comments:
107
    def _get_format_string(self):
108
        """Return format string for this exception or None"""
109
        fmt = getattr(self, '_fmt', None)
110
        if fmt is not None:
111
            return fmt
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
112
        fmt = getattr(self, '__doc__', None)
2067.3.2 by Martin Pool
Error cleanup review comments:
113
        if fmt is not None:
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
114
            symbol_versioning.warn("%s uses its docstring as a format, "
115
                    "it should use _fmt instead" % self.__class__.__name__,
116
                    DeprecationWarning)
117
            return fmt
118
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
119
            % (self.__class__.__name__,
120
               self.__dict__,
121
               getattr(self, '_fmt', None),
122
               )
2067.3.2 by Martin Pool
Error cleanup review comments:
123
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
124
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
125
class BzrNewError(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
126
    """Deprecated error base class."""
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
127
    # base classes should override the docstring with their human-
128
    # readable explanation
129
1685.2.1 by Brian M. Carlson
Add a workaround for usage of the args attribute in exceptions.
130
    def __init__(self, *args, **kwds):
131
        # XXX: Use the underlying BzrError to always generate the args attribute
1685.2.2 by Brian M. Carlson
Change the BzrNewError super invocation to a direct call, so it works with 2.4.
132
        # if it doesn't exist.  We can't use super here, because exceptions are
133
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
2067.3.4 by Martin Pool
Error deprecations will come in for 0.13
134
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
135
             'please convert %s to use BzrError instead' 
136
             % self.__class__.__name__,
137
             DeprecationWarning,
138
             stacklevel=2)
1685.2.2 by Brian M. Carlson
Change the BzrNewError super invocation to a direct call, so it works with 2.4.
139
        BzrError.__init__(self, *args)
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
140
        for key, value in kwds.items():
141
            setattr(self, key, value)
142
143
    def __str__(self):
144
        try:
1948.1.6 by John Arbash Meinel
Make BzrNewError always return a str object
145
            # __str__() should always return a 'str' object
146
            # never a 'unicode' object.
147
            s = self.__doc__ % self.__dict__
148
            if isinstance(s, unicode):
149
                return s.encode('utf8')
150
            return s
1910.12.1 by Andrew Bennetts
Catch TypeError in BzrNewError.__str__, and print more information if an exception happens in that.
151
        except (TypeError, NameError, ValueError, KeyError), e:
152
            return 'Unprintable exception %s(%r): %s' \
153
                % (self.__class__.__name__,
154
                   self.__dict__, str(e))
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
155
156
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
157
class AlreadyBuilding(BzrError):
158
    
159
    _fmt = "The tree builder is already building a tree."
160
161
162
class BzrCheckError(BzrError):
163
    
164
    _fmt = "Internal check failed: %(message)s"
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
165
2067.3.2 by Martin Pool
Error cleanup review comments:
166
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
167
1185.16.63 by Martin Pool
- more error conversion
168
    def __init__(self, message):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
169
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
170
        self.message = message
171
172
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
173
class InvalidEntryName(BzrError):
174
    
175
    _fmt = "Invalid entry name: %(name)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
176
2067.3.2 by Martin Pool
Error cleanup review comments:
177
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
178
1185.16.63 by Martin Pool
- more error conversion
179
    def __init__(self, name):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
180
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
181
        self.name = name
182
183
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
184
class InvalidRevisionNumber(BzrError):
185
    
186
    _fmt = "Invalid revision number %(revno)s"
187
1185.16.63 by Martin Pool
- more error conversion
188
    def __init__(self, revno):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
189
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
190
        self.revno = revno
191
192
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
193
class InvalidRevisionId(BzrError):
194
195
    _fmt = "Invalid revision-id {%(revision_id)s} in %(branch)s"
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
196
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
197
    def __init__(self, revision_id, branch):
1668.5.1 by Olaf Conradi
Fix bug in knits when raising InvalidRevisionId without the required
198
        # branch can be any string or object with __str__ defined
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
199
        BzrError.__init__(self)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
200
        self.revision_id = revision_id
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
201
        self.branch = branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
202
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
203
class ReservedId(BzrError):
2229.2.3 by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY
204
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
205
    _fmt = "Reserved revision-id {%(revision_id)s}"
2229.2.3 by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY
206
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
207
    def __init__(self, revision_id):
208
        self.revision_id = revision_id
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
209
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
210
class NoSuchId(BzrError):
211
212
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
1988.2.1 by Robert Collins
WorkingTree has a new api ``unversion`` which allow the unversioning of
213
    
214
    def __init__(self, tree, file_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
215
        BzrError.__init__(self)
1988.2.1 by Robert Collins
WorkingTree has a new api ``unversion`` which allow the unversioning of
216
        self.file_id = file_id
217
        self.tree = tree
218
219
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
220
class InventoryModified(BzrError):
221
222
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
223
            "so a clean inventory cannot be read without data loss.")
224
225
    internal_error = True
226
227
    def __init__(self, tree):
228
        self.tree = tree
229
230
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
231
class NoWorkingTree(BzrError):
232
233
    _fmt = "No WorkingTree exists for %(base)s."
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
234
    
235
    def __init__(self, base):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
236
        BzrError.__init__(self)
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
237
        self.base = base
1506 by Robert Collins
Merge Johns current integration work.
238
239
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
240
class NotBuilding(BzrError):
241
242
    _fmt = "Not currently building a tree."
243
244
245
class NotLocalUrl(BzrError):
246
247
    _fmt = "%(url)s is not a local path."
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
248
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
249
    def __init__(self, url):
250
        self.url = url
251
252
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
253
class WorkingTreeAlreadyPopulated(BzrError):
254
255
    _fmt = """Working tree already populated in %(base)s"""
256
257
    internal_error = True
258
259
    def __init__(self, base):
260
        self.base = base
261
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
262
class BzrCommandError(BzrError):
1740.5.6 by Martin Pool
Clean up many exception classes.
263
    """Error from user command"""
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
264
2067.3.2 by Martin Pool
Error cleanup review comments:
265
    internal_error = False
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
266
267
    # Error from malformed user command; please avoid raising this as a
268
    # generic exception not caused by user input.
1185.54.18 by Aaron Bentley
Noted difference of opinion wrt BzrCommandError
269
    #
270
    # I think it's a waste of effort to differentiate between errors that
271
    # are not intended to be caught anyway.  UI code need not subclass
272
    # BzrCommandError, and non-UI code should not throw a subclass of
273
    # BzrCommandError.  ADHB 20051211
1740.5.6 by Martin Pool
Clean up many exception classes.
274
    def __init__(self, msg):
1948.1.5 by John Arbash Meinel
Make sure BzrCommandError can handle unicode arguments
275
        # Object.__str__() must return a real string
276
        # returning a Unicode string is a python error.
277
        if isinstance(msg, unicode):
278
            self.msg = msg.encode('utf8')
279
        else:
280
            self.msg = msg
1740.5.6 by Martin Pool
Clean up many exception classes.
281
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
282
    def __str__(self):
1740.5.6 by Martin Pool
Clean up many exception classes.
283
        return self.msg
284
285
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
286
class NotWriteLocked(BzrError):
287
288
    _fmt = """%(not_locked)r is not write locked but needs to be."""
289
290
    def __init__(self, not_locked):
291
        self.not_locked = not_locked
292
293
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
294
class BzrOptionError(BzrCommandError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
295
296
    _fmt = "Error in command line options"
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
297
2221.4.1 by Aaron Bentley
Get registry options working
298
2221.4.6 by Aaron Bentley
Improve text and naming
299
class BadOptionValue(BzrError):
2221.4.1 by Aaron Bentley
Get registry options working
300
2221.4.6 by Aaron Bentley
Improve text and naming
301
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
2221.4.1 by Aaron Bentley
Get registry options working
302
303
    def __init__(self, name, value):
304
        BzrError.__init__(self, name=name, value=value)
305
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
306
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
307
class StrictCommitFailed(BzrError):
308
309
    _fmt = "Commit refused because there are unknown files in the tree"
1 by mbp at sourcefrog
import from baz patch-364
310
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
311
1662.1.12 by Martin Pool
Translate unknown sftp errors to PathError, no NoSuchFile
312
# XXX: Should be unified with TransportError; they seem to represent the
313
# same thing
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
314
class PathError(BzrError):
315
    
316
    _fmt = "Generic path error: %(path)r%(extra)s)"
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
317
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
318
    def __init__(self, path, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
319
        BzrError.__init__(self)
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
320
        self.path = path
1908.4.11 by John Arbash Meinel
reverting changes to errors.py and local transport.
321
        if extra:
322
            self.extra = ': ' + str(extra)
323
        else:
324
            self.extra = ''
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
325
326
327
class NoSuchFile(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
328
329
    _fmt = "No such file: %(path)r%(extra)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
330
331
332
class FileExists(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
333
334
    _fmt = "File exists: %(path)r%(extra)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
335
336
2206.1.5 by Marius Kruger
* errors
337
class FilesExist(PathError):
2206.1.7 by Marius Kruger
* errors
338
    """Used when reporting that files do exist"""
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
339
2206.1.7 by Marius Kruger
* errors
340
    _fmt = "File%(plural)s exist: %(paths_as_string)s%(extra)s"
2206.1.5 by Marius Kruger
* errors
341
342
    def __init__(self, paths, extra=None):
343
        # circular import
344
        from bzrlib.osutils import quotefn
345
        BzrError.__init__(self)
346
        self.paths = paths
2206.1.7 by Marius Kruger
* errors
347
        self.paths_as_string = ' '.join(paths)
2206.1.5 by Marius Kruger
* errors
348
        if extra:
349
            self.extra = ': ' + str(extra)
350
        else:
351
            self.extra = ''
2206.1.7 by Marius Kruger
* errors
352
        if len(paths) > 1:
353
            self.plural = 's'
354
        else:
355
            self.plural = ''
2206.1.5 by Marius Kruger
* errors
356
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
357
2206.1.4 by Marius Kruger
Improved WorkingTree.move excptions. (as requested)
358
class NotADirectory(PathError):
359
360
    _fmt = "%(path)r is not a directory %(extra)s"
361
362
363
class NotInWorkingDirectory(PathError):
364
2220.1.3 by Marius Kruger
* errors.py
365
    _fmt = "%(path)r is not in the working directory %(extra)s"
2206.1.4 by Marius Kruger
Improved WorkingTree.move excptions. (as requested)
366
367
1553.5.10 by Martin Pool
New DirectoryNotEmpty exception, and raise this from local and memory
368
class DirectoryNotEmpty(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
369
370
    _fmt = "Directory not empty: %(path)r%(extra)s"
1553.5.10 by Martin Pool
New DirectoryNotEmpty exception, and raise this from local and memory
371
372
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
373
class ReadingCompleted(BzrError):
374
    
375
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
376
            "called upon it - the request has been completed and no more "
377
            "data may be read.")
378
379
    internal_error = True
2018.2.28 by Andrew Bennetts
Changes in response to review: re-use _base_curl, rather than keeping a seperate _post_curl object; add docstring to test_http.RecordingServer, set is_user_error on some new exceptions.
380
2018.2.4 by Robert Collins
separate out the client medium from the client encoding protocol for the smart server.
381
    def __init__(self, request):
382
        self.request = request
383
384
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
385
class ResourceBusy(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
386
387
    _fmt = "Device or resource busy: %(path)r%(extra)s"
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
388
389
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
390
class PermissionDenied(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
391
392
    _fmt = "Permission denied: %(path)r%(extra)s"
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
393
394
1185.85.76 by John Arbash Meinel
Adding an InvalidURL so transports can report they expect utf-8 quoted paths. Updated tests
395
class InvalidURL(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
396
397
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
1185.85.76 by John Arbash Meinel
Adding an InvalidURL so transports can report they expect utf-8 quoted paths. Updated tests
398
399
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
400
class InvalidURLJoin(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
401
402
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
403
404
    def __init__(self, msg, base, args):
405
        PathError.__init__(self, base, msg)
2027.2.2 by Marien Zwart
Fixes for python 2.5.
406
        self.args = [base] + list(args)
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
407
408
1843.1.1 by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info
409
class UnsupportedProtocol(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
410
411
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
1843.1.1 by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info
412
413
    def __init__(self, url, extra):
414
        PathError.__init__(self, url, extra=extra)
415
416
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
417
class ShortReadvError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
418
419
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
420
2067.3.2 by Martin Pool
Error cleanup review comments:
421
    internal_error = True
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
422
2001.3.3 by John Arbash Meinel
review feedback: add the actual count written to ShortReadvError
423
    def __init__(self, path, offset, length, actual, extra=None):
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
424
        PathError.__init__(self, path, extra=extra)
425
        self.offset = offset
426
        self.length = length
2001.3.3 by John Arbash Meinel
review feedback: add the actual count written to ShortReadvError
427
        self.actual = actual
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
428
429
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
430
class PathNotChild(BzrError):
431
432
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
433
2067.3.2 by Martin Pool
Error cleanup review comments:
434
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
435
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
436
    def __init__(self, path, base, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
437
        BzrError.__init__(self)
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
438
        self.path = path
439
        self.base = base
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
440
        if extra:
441
            self.extra = ': ' + str(extra)
442
        else:
443
            self.extra = ''
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
444
445
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
446
class InvalidNormalization(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
447
448
    _fmt = "Path %(path)r is not unicode normalized"
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
449
450
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
451
# TODO: This is given a URL; we try to unescape it but doing that from inside
452
# the exception object is a bit undesirable.
453
# TODO: Probably this behavior of should be a common superclass 
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
454
class NotBranchError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
455
456
    _fmt = "Not a branch: %(path)s"
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
457
458
    def __init__(self, path):
459
       import bzrlib.urlutils as urlutils
1908.4.11 by John Arbash Meinel
reverting changes to errors.py and local transport.
460
       self.path = urlutils.unescape_for_display(path, 'ascii')
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
461
462
463
class AlreadyBranchError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
464
465
    _fmt = "Already a branch: %(path)s."
1662.1.19 by Martin Pool
Better error message when initting existing tree
466
467
468
class BranchExistsWithoutWorkingTree(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
469
470
    _fmt = "Directory contains a branch, but no working tree \
2067.3.2 by Martin Pool
Error cleanup review comments:
471
(use bzr checkout if you wish to build a working tree): %(path)s"
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
472
573 by Martin Pool
- new exception NotBranchError
473
1755.3.6 by John Arbash Meinel
Add a test suite for Atomic File, and clean it up so that it really does set the mode properly.
474
class AtomicFileAlreadyClosed(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
475
476
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
1755.3.6 by John Arbash Meinel
Add a test suite for Atomic File, and clean it up so that it really does set the mode properly.
477
478
    def __init__(self, path, function):
479
        PathError.__init__(self, path=path, extra=None)
480
        self.function = function
481
482
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
483
class InaccessibleParent(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
484
485
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
486
487
    def __init__(self, path, base):
488
        PathError.__init__(self, path)
489
        self.base = base
490
491
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
492
class NoRepositoryPresent(BzrError):
493
494
    _fmt = "No repository present: %(path)r"
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
495
    def __init__(self, bzrdir):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
496
        BzrError.__init__(self)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
497
        self.path = bzrdir.transport.clone('..').base
498
499
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
500
class FileInWrongBranch(BzrError):
501
502
    _fmt = "File %(path)s in not in branch %(branch_base)s."
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
503
1185.35.32 by Aaron Bentley
Fixed handling of files in mixed branches
504
    def __init__(self, branch, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
505
        BzrError.__init__(self)
1185.35.32 by Aaron Bentley
Fixed handling of files in mixed branches
506
        self.branch = branch
507
        self.branch_base = branch.base
508
        self.path = path
509
510
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
511
class UnsupportedFormatError(BzrError):
512
    
513
    _fmt = "Unsupported branch format: %(format)s"
514
515
516
class UnknownFormatError(BzrError):
517
    
518
    _fmt = "Unknown branch format: %(format)r"
519
520
521
class IncompatibleFormat(BzrError):
522
    
523
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
524
525
    def __init__(self, format, bzrdir_format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
526
        BzrError.__init__(self)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
527
        self.format = format
528
        self.bzrdir = bzrdir_format
529
530
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
531
class IncompatibleRevision(BzrError):
532
    
533
    _fmt = "Revision is not compatible with %(repo_format)s"
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
534
535
    def __init__(self, repo_format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
536
        BzrError.__init__(self)
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
537
        self.repo_format = repo_format
538
539
2206.1.5 by Marius Kruger
* errors
540
class AlreadyVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
541
    """Used when a path is expected not to be versioned, but it is."""
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
542
2206.1.7 by Marius Kruger
* errors
543
    _fmt = "%(context_info)s%(path)s is already versioned"
2206.1.5 by Marius Kruger
* errors
544
2206.1.7 by Marius Kruger
* errors
545
    def __init__(self, path, context_info=None):
2206.1.5 by Marius Kruger
* errors
546
        """Construct a new NotVersionedError.
547
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
548
        :param path: This is the path which is versioned,
2206.1.5 by Marius Kruger
* errors
549
        which should be in a user friendly form.
2206.1.7 by Marius Kruger
* errors
550
        :param context_info: If given, this is information about the context,
2206.1.5 by Marius Kruger
* errors
551
        which could explain why this is expected to not be versioned.
552
        """
553
        BzrError.__init__(self)
554
        self.path = path
2206.1.7 by Marius Kruger
* errors
555
        if context_info is None:
556
            self.context_info = ''
2206.1.5 by Marius Kruger
* errors
557
        else:
2206.1.7 by Marius Kruger
* errors
558
            self.context_info = context_info + ". "
2206.1.5 by Marius Kruger
* errors
559
560
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
561
class NotVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
562
    """Used when a path is expected to be versioned, but it is not."""
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
563
2206.1.7 by Marius Kruger
* errors
564
    _fmt = "%(context_info)s%(path)s is not versioned"
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
565
2206.1.7 by Marius Kruger
* errors
566
    def __init__(self, path, context_info=None):
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
567
        """Construct a new NotVersionedError.
568
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
569
        :param path: This is the path which is not versioned,
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
570
        which should be in a user friendly form.
2206.1.7 by Marius Kruger
* errors
571
        :param context_info: If given, this is information about the context,
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
572
        which could explain why this is expected to be versioned.
573
        """
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
574
        BzrError.__init__(self)
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
575
        self.path = path
2206.1.7 by Marius Kruger
* errors
576
        if context_info is None:
577
            self.context_info = ''
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
578
        else:
2206.1.7 by Marius Kruger
* errors
579
            self.context_info = context_info + ". "
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
580
581
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
582
class PathsNotVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
583
    """Used when reporting several paths which are not versioned"""
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
584
585
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
1658.1.9 by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619)
586
587
    def __init__(self, paths):
588
        from bzrlib.osutils import quotefn
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
589
        BzrError.__init__(self)
1658.1.9 by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619)
590
        self.paths = paths
591
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
592
593
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
594
class PathsDoNotExist(BzrError):
595
2206.1.5 by Marius Kruger
* errors
596
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
1662.1.14 by Martin Pool
(PathsDoNotExist) review style comments
597
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
598
    # used when reporting that paths are neither versioned nor in the working
599
    # tree
600
2206.1.5 by Marius Kruger
* errors
601
    def __init__(self, paths, extra=None):
1662.1.14 by Martin Pool
(PathsDoNotExist) review style comments
602
        # circular import
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
603
        from bzrlib.osutils import quotefn
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
604
        BzrError.__init__(self)
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
605
        self.paths = paths
606
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
2206.1.5 by Marius Kruger
* errors
607
        if extra:
608
            self.extra = ': ' + str(extra)
609
        else:
610
            self.extra = ''
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
611
612
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
613
class BadFileKindError(BzrError):
614
615
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
616
617
618
class ForbiddenControlFileError(BzrError):
619
620
    _fmt = "Cannot operate on %(filename)s because it is a control file"
621
622
623
class LockError(BzrError):
624
625
    _fmt = "Lock error: %(message)s"
2221.2.2 by Aaron Bentley
PEP8-correctness
626
2221.2.1 by Aaron Bentley
Make most lock errors internal
627
    internal_error = True
2067.3.2 by Martin Pool
Error cleanup review comments:
628
1185.16.63 by Martin Pool
- more error conversion
629
    # All exceptions from the lock/unlock functions should be from
630
    # this exception class.  They will be translated as necessary. The
631
    # original exception is available as e.original_error
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
632
    #
633
    # New code should prefer to raise specific subclasses
634
    def __init__(self, message):
635
        self.message = message
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
636
637
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
638
class CommitNotPossible(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
639
640
    _fmt = "A commit was attempted but we do not have a write lock open."
2067.3.2 by Martin Pool
Error cleanup review comments:
641
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
642
    def __init__(self):
643
        pass
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
644
645
646
class AlreadyCommitted(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
647
648
    _fmt = "A rollback was requested, but is not able to be accomplished."
2067.3.2 by Martin Pool
Error cleanup review comments:
649
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
650
    def __init__(self):
651
        pass
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
652
653
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
654
class ReadOnlyError(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
655
656
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
657
1553.5.33 by Martin Pool
LockDir review comment fixes
658
    def __init__(self, obj):
659
        self.obj = obj
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
660
661
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
662
class OutSideTransaction(BzrError):
663
664
    _fmt = "A transaction related operation was attempted after the transaction finished."
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
665
666
1553.5.36 by Martin Pool
Clean up duplicate BranchNotLocked error and rename to ObjectNotLocked
667
class ObjectNotLocked(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
668
669
    _fmt = "%(obj)r is not locked"
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
670
1553.5.36 by Martin Pool
Clean up duplicate BranchNotLocked error and rename to ObjectNotLocked
671
    # this can indicate that any particular object is not locked; see also
672
    # LockNotHeld which means that a particular *lock* object is not held by
673
    # the caller -- perhaps they should be unified.
674
    def __init__(self, obj):
675
        self.obj = obj
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
676
677
678
class ReadOnlyObjectDirtiedError(ReadOnlyError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
679
680
    _fmt = "Cannot change object %(obj)r in read only transaction"
2067.3.2 by Martin Pool
Error cleanup review comments:
681
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
682
    def __init__(self, obj):
683
        self.obj = obj
684
685
686
class UnlockableTransport(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
687
688
    _fmt = "Cannot lock: transport is read only: %(transport)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
689
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
690
    def __init__(self, transport):
691
        self.transport = transport
692
693
694
class LockContention(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
695
696
    _fmt = "Could not acquire lock %(lock)s"
2221.2.1 by Aaron Bentley
Make most lock errors internal
697
    # TODO: show full url for lock, combining the transport and relative
698
    # bits?
2221.2.2 by Aaron Bentley
PEP8-correctness
699
2221.2.1 by Aaron Bentley
Make most lock errors internal
700
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
701
    
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
702
    def __init__(self, lock):
703
        self.lock = lock
704
705
1553.5.23 by Martin Pool
Start LockDir.confirm method and LockBroken exception
706
class LockBroken(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
707
708
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
2221.2.2 by Aaron Bentley
PEP8-correctness
709
2221.2.1 by Aaron Bentley
Make most lock errors internal
710
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
711
1553.5.23 by Martin Pool
Start LockDir.confirm method and LockBroken exception
712
    def __init__(self, lock):
713
        self.lock = lock
714
715
1553.5.27 by Martin Pool
Confirm that only the intended holder of a lock was broken.
716
class LockBreakMismatch(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
717
718
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
2221.2.2 by Aaron Bentley
PEP8-correctness
719
2221.2.1 by Aaron Bentley
Make most lock errors internal
720
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
721
1553.5.27 by Martin Pool
Confirm that only the intended holder of a lock was broken.
722
    def __init__(self, lock, holder, target):
723
        self.lock = lock
724
        self.holder = holder
725
        self.target = target
726
727
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
728
class LockNotHeld(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
729
730
    _fmt = "Lock not held: %(lock)s"
2221.2.2 by Aaron Bentley
PEP8-correctness
731
2221.2.1 by Aaron Bentley
Make most lock errors internal
732
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
733
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
734
    def __init__(self, lock):
735
        self.lock = lock
736
737
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
738
class PointlessCommit(BzrError):
739
740
    _fmt = "No changes to commit"
741
742
743
class UpgradeReadonly(BzrError):
744
745
    _fmt = "Upgrade URL cannot work with readonly URLs."
746
747
748
class UpToDateFormat(BzrError):
749
750
    _fmt = "The branch format %(format)s is already at the most recent format."
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
751
752
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
753
        BzrError.__init__(self)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
754
        self.format = format
755
756
1185.22.1 by Michael Ellerman
Implement strict commits with --strict flag.
757
class StrictCommitFailed(Exception):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
758
759
    _fmt = "Commit refused because there are unknowns in the tree."
760
761
762
class NoSuchRevision(BzrError):
763
764
    _fmt = "Branch %(branch)s has no revision %(revision)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
765
2067.3.2 by Martin Pool
Error cleanup review comments:
766
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
767
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
768
    def __init__(self, branch, revision):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
769
        BzrError.__init__(self, branch=branch, revision=revision)
770
771
772
class NoSuchRevisionSpec(BzrError):
773
774
    _fmt = "No namespace registered for string: %(spec)r"
1948.4.25 by John Arbash Meinel
Check that invalid specs are properly handled
775
776
    def __init__(self, spec):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
777
        BzrError.__init__(self, spec=spec)
778
779
780
class InvalidRevisionSpec(BzrError):
781
782
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
783
784
    def __init__(self, spec, branch, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
785
        BzrError.__init__(self, branch=branch, spec=spec)
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
786
        if extra:
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
787
            self.extra = '\n' + str(extra)
1948.4.1 by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers
788
        else:
789
            self.extra = ''
1740.5.6 by Martin Pool
Clean up many exception classes.
790
791
1192 by Martin Pool
- clean up code for retrieving stored inventories
792
class HistoryMissing(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
793
794
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
795
796
797
class DivergedBranches(BzrError):
798
    
799
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
1740.5.6 by Martin Pool
Clean up many exception classes.
800
2067.3.2 by Martin Pool
Error cleanup review comments:
801
    internal_error = False
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
802
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
803
    def __init__(self, branch1, branch2):
804
        self.branch1 = branch1
805
        self.branch2 = branch2
806
1390 by Robert Collins
pair programming worx... merge integration and weave
807
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
808
class UnrelatedBranches(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
809
810
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
811
812
    internal_error = False
1740.5.6 by Martin Pool
Clean up many exception classes.
813
814
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
815
class NoCommonAncestor(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
816
    
817
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
818
974.1.80 by Aaron Bentley
Improved merge error handling and testing
819
    def __init__(self, revision_a, revision_b):
1740.5.6 by Martin Pool
Clean up many exception classes.
820
        self.revision_a = revision_a
821
        self.revision_b = revision_b
974.1.80 by Aaron Bentley
Improved merge error handling and testing
822
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
823
974.1.80 by Aaron Bentley
Improved merge error handling and testing
824
class NoCommonRoot(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
825
826
    _fmt = "Revisions are not derived from the same root: " \
827
           "%(revision_a)s %(revision_b)s."
828
974.1.80 by Aaron Bentley
Improved merge error handling and testing
829
    def __init__(self, revision_a, revision_b):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
830
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
831
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
832
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
833
class NotAncestor(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
834
835
    _fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
836
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
837
    def __init__(self, rev_id, not_ancestor_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
838
        BzrError.__init__(self, rev_id=rev_id,
839
            not_ancestor_id=not_ancestor_id)
1185.1.12 by Robert Collins
merge in lsdiff/filterdiff friendliness
840
841
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
842
class InstallFailed(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
843
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
844
    def __init__(self, revisions):
2116.3.1 by John Arbash Meinel
Cleanup error tests
845
        revision_str = ", ".join(str(r) for r in revisions)
846
        msg = "Could not install revisions:\n%s" % revision_str
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
847
        BzrError.__init__(self, msg)
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
848
        self.revisions = revisions
1154 by Martin Pool
- fix imports for moved errors
849
850
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
851
class AmbiguousBase(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
852
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
853
    def __init__(self, bases):
854
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
855
                DeprecationWarning)
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
856
        msg = "The correct base is unclear, because %s are all equally close" %\
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
857
            ", ".join(bases)
858
        BzrError.__init__(self, msg)
859
        self.bases = bases
860
861
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
862
class NoCommits(BzrError):
863
864
    _fmt = "Branch %(branch)s has no commits."
1948.4.20 by John Arbash Meinel
Make NoCommits a BzrNewError
865
974.1.80 by Aaron Bentley
Improved merge error handling and testing
866
    def __init__(self, branch):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
867
        BzrError.__init__(self, branch=branch)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
868
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
869
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
870
class UnlistableStore(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
871
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
872
    def __init__(self, store):
873
        BzrError.__init__(self, "Store %s is not listable" % store)
874
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
875
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
876
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
877
class UnlistableBranch(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
878
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
879
    def __init__(self, br):
880
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1392 by Robert Collins
reinstate testfetch test case
881
882
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
883
class BoundBranchOutOfDate(BzrError):
884
885
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
2067.3.2 by Martin Pool
Error cleanup review comments:
886
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
887
    def __init__(self, branch, master):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
888
        BzrError.__init__(self)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
889
        self.branch = branch
890
        self.master = master
891
892
        
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
893
class CommitToDoubleBoundBranch(BzrError):
894
895
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
2067.3.2 by Martin Pool
Error cleanup review comments:
896
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
897
    def __init__(self, branch, master, remote):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
898
        BzrError.__init__(self)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
899
        self.branch = branch
900
        self.master = master
901
        self.remote = remote
902
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
903
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
904
class OverwriteBoundBranch(BzrError):
905
906
    _fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
907
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
908
    def __init__(self, branch):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
909
        BzrError.__init__(self)
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
910
        self.branch = branch
911
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
912
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
913
class BoundBranchConnectionFailure(BzrError):
914
915
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
916
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
917
    def __init__(self, branch, target, error):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
918
        BzrError.__init__(self)
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
919
        self.branch = branch
920
        self.target = target
921
        self.error = error
922
923
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
924
class WeaveError(BzrError):
925
926
    _fmt = "Error in processing weave: %(message)s"
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
927
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
928
    def __init__(self, message=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
929
        BzrError.__init__(self)
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
930
        self.message = message
931
932
933
class WeaveRevisionAlreadyPresent(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
934
935
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
936
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
937
    def __init__(self, revision_id, weave):
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
938
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
939
        WeaveError.__init__(self)
940
        self.revision_id = revision_id
941
        self.weave = weave
942
943
944
class WeaveRevisionNotPresent(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
945
946
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
947
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
948
    def __init__(self, revision_id, weave):
949
        WeaveError.__init__(self)
950
        self.revision_id = revision_id
951
        self.weave = weave
952
953
954
class WeaveFormatError(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
955
956
    _fmt = "Weave invariant violated: %(what)s"
1563.2.10 by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations.
957
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
958
    def __init__(self, what):
959
        WeaveError.__init__(self)
960
        self.what = what
961
962
963
class WeaveParentMismatch(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
964
965
    _fmt = "Parents are mismatched between two revisions."
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
966
    
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
967
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
968
class WeaveInvalidChecksum(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
969
970
    _fmt = "Text did not match it's checksum: %(message)s"
971
972
973
class WeaveTextDiffers(WeaveError):
974
975
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
976
977
    def __init__(self, revision_id, weave_a, weave_b):
978
        WeaveError.__init__(self)
979
        self.revision_id = revision_id
980
        self.weave_a = weave_a
981
        self.weave_b = weave_b
982
983
984
class WeaveTextDiffers(WeaveError):
985
986
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
987
988
    def __init__(self, revision_id, weave_a, weave_b):
989
        WeaveError.__init__(self)
990
        self.revision_id = revision_id
991
        self.weave_a = weave_a
992
        self.weave_b = weave_b
993
994
995
class VersionedFileError(BzrError):
996
    
997
    _fmt = "Versioned file error"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
998
999
1000
class RevisionNotPresent(VersionedFileError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1001
    
1002
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1003
1004
    def __init__(self, revision_id, file_id):
1005
        VersionedFileError.__init__(self)
1006
        self.revision_id = revision_id
1007
        self.file_id = file_id
1008
1009
1010
class RevisionAlreadyPresent(VersionedFileError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1011
    
1012
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1013
1014
    def __init__(self, revision_id, file_id):
1015
        VersionedFileError.__init__(self)
1016
        self.revision_id = revision_id
1017
        self.file_id = file_id
1018
1019
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1020
class KnitError(BzrError):
1021
    
1022
    _fmt = "Knit error"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1023
2208.1.1 by John Arbash Meinel
Making KnitError and children internal errors.
1024
    internal_error = True
1025
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1026
1027
class KnitHeaderError(KnitError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1028
2171.1.1 by John Arbash Meinel
Knit index files should ignore empty indexes rather than consider them corrupt.
1029
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1030
2171.1.1 by John Arbash Meinel
Knit index files should ignore empty indexes rather than consider them corrupt.
1031
    def __init__(self, badline, filename):
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1032
        KnitError.__init__(self)
1033
        self.badline = badline
2171.1.1 by John Arbash Meinel
Knit index files should ignore empty indexes rather than consider them corrupt.
1034
        self.filename = filename
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1035
1036
1037
class KnitCorrupt(KnitError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1038
1039
    _fmt = "Knit %(filename)s corrupt: %(how)s"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1040
1041
    def __init__(self, filename, how):
1042
        KnitError.__init__(self)
1043
        self.filename = filename
1044
        self.how = how
1045
1046
2196.2.5 by John Arbash Meinel
Add an exception class when the knit index storage method is unknown, and properly test for it
1047
class KnitIndexUnknownMethod(KnitError):
1048
    """Raised when we don't understand the storage method.
1049
1050
    Currently only 'fulltext' and 'line-delta' are supported.
1051
    """
1052
    
1053
    _fmt = ("Knit index %(filename)s does not have a known method"
1054
            " in options: %(options)r")
1055
1056
    def __init__(self, filename, options):
1057
        KnitError.__init__(self)
1058
        self.filename = filename
1059
        self.options = options
1060
1061
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1062
class NoSuchExportFormat(BzrError):
1063
    
1064
    _fmt = "Export format %(format)r not supported"
1065
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
1066
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1067
        BzrError.__init__(self)
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
1068
        self.format = format
1069
1070
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1071
class TransportError(BzrError):
1072
    
1073
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1824.2.1 by Johan Rydberg
Let TransportError inherit BzrNerError.
1074
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1075
    def __init__(self, msg=None, orig_error=None):
1076
        if msg is None and orig_error is not None:
1077
            msg = str(orig_error)
1824.2.1 by Johan Rydberg
Let TransportError inherit BzrNerError.
1078
        if orig_error is None:
1079
            orig_error = ''
1080
        if msg is None:
1081
            msg =  ''
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1082
        self.msg = msg
1083
        self.orig_error = orig_error
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1084
        BzrError.__init__(self)
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1085
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1086
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1087
class TooManyConcurrentRequests(BzrError):
1088
1089
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
1090
            "Be sure to finish_writing and finish_reading on the "
1091
            "current request that is open.")
1092
1093
    internal_error = True
1094
1095
    def __init__(self, medium):
1096
        self.medium = medium
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1097
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1098
1910.19.14 by Robert Collins
Fix up all tests to pass, remove a couple more deprecated function calls, and break the dependency on sftp for the smart transport.
1099
class SmartProtocolError(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1100
1101
    _fmt = "Generic bzr smart protocol error: %(details)s"
1910.19.13 by Andrew Bennetts
Address various review comments.
1102
1103
    def __init__(self, details):
1104
        self.details = details
1105
1106
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1107
# A set of semi-meaningful errors which can be thrown
1108
class TransportNotPossible(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1109
1110
    _fmt = "Transport operation not possible: %(msg)s %(orig_error)s"
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1111
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
1112
1113
class ConnectionError(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1114
1115
    _fmt = "Connection error: %(msg)s %(orig_error)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
1116
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1117
2052.4.4 by John Arbash Meinel
Create a SocketConnectionError to make creating nice errors easier
1118
class SocketConnectionError(ConnectionError):
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1119
1120
    _fmt = "%(msg)s %(host)s%(port)s%(orig_error)s"
2052.4.4 by John Arbash Meinel
Create a SocketConnectionError to make creating nice errors easier
1121
1122
    def __init__(self, host, port=None, msg=None, orig_error=None):
1123
        if msg is None:
1124
            msg = 'Failed to connect to'
1125
        if orig_error is None:
1126
            orig_error = ''
1127
        else:
1128
            orig_error = '; ' + str(orig_error)
1129
        ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
1130
        self.host = host
1131
        if port is None:
1132
            self.port = ''
1133
        else:
1134
            self.port = ':%s' % port
1135
1136
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1137
class ConnectionReset(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1138
1139
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1140
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1141
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1142
class InvalidRange(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1143
1144
    _fmt = "Invalid range access in %(path)s at %(offset)s."
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1145
    
1146
    def __init__(self, path, offset):
1147
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1148
                                       % (path, offset)))
1979.1.1 by John Arbash Meinel
Fix bug #57723, parse boundary="" correctly, since Squid uses it
1149
        self.path = path
1150
        self.offset = offset
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1151
1152
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1153
class InvalidHttpResponse(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1154
1155
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1156
1786.1.31 by John Arbash Meinel
Update http errors to properly use BzrNewError
1157
    def __init__(self, path, msg, orig_error=None):
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1158
        self.path = path
1786.1.31 by John Arbash Meinel
Update http errors to properly use BzrNewError
1159
        TransportError.__init__(self, msg, orig_error=orig_error)
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1160
1161
1162
class InvalidHttpRange(InvalidHttpResponse):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1163
1164
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1786.1.13 by John Arbash Meinel
Found a few bugs in error handling code, updated tests
1165
    
1166
    def __init__(self, path, range, msg):
1167
        self.range = range
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1168
        InvalidHttpResponse.__init__(self, path, msg)
1169
1170
1171
class InvalidHttpContentType(InvalidHttpResponse):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1172
1173
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1174
    
1175
    def __init__(self, path, ctype, msg):
1176
        self.ctype = ctype
1177
        InvalidHttpResponse.__init__(self, path, msg)
1786.1.13 by John Arbash Meinel
Found a few bugs in error handling code, updated tests
1178
1179
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
1180
class ConflictsInTree(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1181
1182
    _fmt = "Working tree has conflicts."
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1183
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1184
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1185
class ParseConfigError(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1186
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1187
    def __init__(self, errors, filename):
1188
        if filename is None:
1189
            filename = ""
1190
        message = "Error(s) parsing config file %s:\n%s" % \
1191
            (filename, ('\n'.join(e.message for e in errors)))
1192
        BzrError.__init__(self, message)
1185.12.52 by Aaron Bentley
Merged more config stuff from Robert
1193
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1194
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1195
class NoEmailInUsername(BzrError):
1196
1197
    _fmt = "%(username)r does not seem to contain a reasonable email address"
2055.2.2 by John Arbash Meinel
Switch extract_email_address() to use a more specific exception
1198
1199
    def __init__(self, username):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1200
        BzrError.__init__(self)
2055.2.2 by John Arbash Meinel
Switch extract_email_address() to use a more specific exception
1201
        self.username = username
1202
1203
1442.1.58 by Robert Collins
gpg signing of content
1204
class SigningFailed(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1205
1206
    _fmt = "Failed to gpg sign data with command %(command_line)r"
1207
1442.1.58 by Robert Collins
gpg signing of content
1208
    def __init__(self, command_line):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1209
        BzrError.__init__(self, command_line=command_line)
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1210
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1211
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1212
class WorkingTreeNotRevision(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1213
1214
    _fmt = ("The working tree for %(basedir)s has changed since" 
1215
            " the last commit, but weave merge requires that it be"
1216
            " unchanged")
1217
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1218
    def __init__(self, tree):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1219
        BzrError.__init__(self, basedir=tree.basedir)
1220
1221
1222
class CantReprocessAndShowBase(BzrError):
1223
1224
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
1225
           "the relationship of conflicting lines to the base"
1226
1227
1228
class GraphCycleError(BzrError):
1229
1230
    _fmt = "Cycle in graph %(graph)r"
2067.3.2 by Martin Pool
Error cleanup review comments:
1231
1185.16.114 by mbp at sourcefrog
Improved topological sort
1232
    def __init__(self, graph):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1233
        BzrError.__init__(self)
1185.16.114 by mbp at sourcefrog
Improved topological sort
1234
        self.graph = graph
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1235
1505.1.23 by John Arbash Meinel
Whitespace cleanup of bzrlib.errors
1236
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1237
class WritingCompleted(BzrError):
1238
1239
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1240
            "called upon it - accept bytes may not be called anymore.")
1241
1242
    internal_error = True
1243
1244
    def __init__(self, request):
1245
        self.request = request
1246
1247
1248
class WritingNotComplete(BzrError):
1249
1250
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1251
            "called upon it - until the write phase is complete no "
1252
            "data may be read.")
1253
1254
    internal_error = True
1255
1256
    def __init__(self, request):
1257
        self.request = request
1258
1259
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1260
class NotConflicted(BzrError):
1261
1262
    _fmt = "File %(filename)s is not conflicted."
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1263
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1264
    def __init__(self, filename):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1265
        BzrError.__init__(self)
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1266
        self.filename = filename
1185.35.13 by Aaron Bentley
Merged Martin
1267
1505.1.23 by John Arbash Meinel
Whitespace cleanup of bzrlib.errors
1268
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1269
class MediumNotConnected(BzrError):
1270
1271
    _fmt = """The medium '%(medium)s' is not connected."""
1272
1273
    internal_error = True
2018.2.3 by Andrew Bennetts
Starting factoring out the smart server client "medium" from the protocol.
1274
1275
    def __init__(self, medium):
1276
        self.medium = medium
1277
1278
1492 by Robert Collins
Support decoration of commands.
1279
class MustUseDecorated(Exception):
2067.3.2 by Martin Pool
Error cleanup review comments:
1280
    
1281
    _fmt = """A decorating function has requested its original command be used."""
1282
    
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1283
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1284
class NoBundleFound(BzrError):
1285
1286
    _fmt = "No bundle was found in %(filename)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
1287
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1288
    def __init__(self, filename):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1289
        BzrError.__init__(self)
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1290
        self.filename = filename
1291
1292
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1293
class BundleNotSupported(BzrError):
1294
1295
    _fmt = "Unable to handle bundle version %(version)s: %(msg)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
1296
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1297
    def __init__(self, version, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1298
        BzrError.__init__(self)
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1299
        self.version = version
1300
        self.msg = msg
1301
1302
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1303
class MissingText(BzrError):
1304
1305
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1306
1185.35.42 by Aaron Bentley
Fixed fetch to be safer wrt ghosts and corrupt branches
1307
    def __init__(self, branch, text_revision, file_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1308
        BzrError.__init__(self)
1185.35.42 by Aaron Bentley
Fixed fetch to be safer wrt ghosts and corrupt branches
1309
        self.branch = branch
1310
        self.base = branch.base
1311
        self.text_revision = text_revision
1312
        self.file_id = file_id
1534.7.5 by Aaron Bentley
Got unique_add under test
1313
1505.1.23 by John Arbash Meinel
Whitespace cleanup of bzrlib.errors
1314
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1315
class DuplicateKey(BzrError):
1316
1317
    _fmt = "Key %(key)s is already present in map"
1318
1319
1320
class MalformedTransform(BzrError):
1321
1322
    _fmt = "Tree transform is malformed %(conflicts)r"
1323
1324
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1325
class NoFinalPath(BzrError):
1326
1327
    _fmt = ("No final name for trans_id %(trans_id)r\n"
1328
            "file-id: %(file_id)r\n"
1329
            "root trans-id: %(root_trans_id)r\n")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
1330
1331
    def __init__(self, trans_id, transform):
1332
        self.trans_id = trans_id
1333
        self.file_id = transform.final_file_id(trans_id)
1334
        self.root_trans_id = transform.root
1335
1336
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1337
class BzrBadParameter(BzrError):
1338
1339
    _fmt = "Bad parameter: %(param)r"
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1340
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1341
    # This exception should never be thrown, but it is a base class for all
1342
    # parameter-to-function errors.
1343
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1344
    def __init__(self, param):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1345
        BzrError.__init__(self)
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1346
        self.param = param
1534.7.32 by Aaron Bentley
Got conflict handling working when conflicts involve existing files
1347
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1348
1185.65.29 by Robert Collins
Implement final review suggestions.
1349
class BzrBadParameterNotUnicode(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1350
1351
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1352
1353
1354
class ReusingTransform(BzrError):
1355
1356
    _fmt = "Attempt to reuse a transform that has already been applied."
1357
1358
1359
class CantMoveRoot(BzrError):
1360
1361
    _fmt = "Moving the root directory is not supported at this time"
1185.65.29 by Robert Collins
Implement final review suggestions.
1362
1534.7.120 by Aaron Bentley
PEP8 fixes
1363
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1364
class BzrMoveFailedError(BzrError):
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1365
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1366
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1367
2220.1.3 by Marius Kruger
* errors.py
1368
    def __init__(self, from_path='', to_path='', extra=None):
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1369
        BzrError.__init__(self)
1370
        if extra:
1371
            self.extra = ': ' + str(extra)
1372
        else:
1373
            self.extra = ''
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1374
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1375
        has_from = len(from_path) > 0
1376
        has_to = len(to_path) > 0
1377
        if has_from:
1378
            self.from_path = osutils.splitpath(from_path)[-1]
1379
        else:
1380
            self.from_path = ''
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1381
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1382
        if has_to:
1383
            self.to_path = osutils.splitpath(to_path)[-1]
1384
        else:
1385
            self.to_path = ''
1386
1387
        self.operator = ""
1388
        if has_from and has_to:
1389
            self.operator = " =>"
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1390
        elif has_from:
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1391
            self.from_path = "from " + from_path
1392
        elif has_to:
1393
            self.operator = "to"
1394
        else:
1395
            self.operator = "file"
1396
1397
1398
class BzrRenameFailedError(BzrMoveFailedError):
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1399
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1400
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1401
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1402
    def __init__(self, from_path, to_path, extra=None):
1403
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1404
1405
1185.65.29 by Robert Collins
Implement final review suggestions.
1406
class BzrBadParameterNotString(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1407
1408
    _fmt = "Parameter %(param)s is not a string or unicode string."
1185.62.24 by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it.
1409
1410
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1411
class BzrBadParameterMissing(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1412
1413
    _fmt = "Parameter $(param)s is required but not present."
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1414
1415
1666.1.6 by Robert Collins
Make knit the default format.
1416
class BzrBadParameterUnicode(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1417
1418
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
1666.1.6 by Robert Collins
Make knit the default format.
1419
1420
1421
class BzrBadParameterContainsNewline(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1422
1423
    _fmt = "Parameter %(param)s contains a newline."
1424
1425
1426
class DependencyNotPresent(BzrError):
1427
1428
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1185.62.24 by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it.
1429
1430
    def __init__(self, library, error):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1431
        BzrError.__init__(self, library=library, error=error)
1185.62.24 by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it.
1432
1433
1434
class ParamikoNotPresent(DependencyNotPresent):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1435
1436
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1185.62.24 by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it.
1437
1438
    def __init__(self, error):
1439
        DependencyNotPresent.__init__(self, 'paramiko', error)
1440
1441
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1442
class PointlessMerge(BzrError):
1443
1444
    _fmt = "Nothing to merge."
1445
1446
1447
class UninitializableFormat(BzrError):
1448
1449
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1450
1451
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1452
        BzrError.__init__(self)
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1453
        self.format = format
1551.3.4 by Aaron Bentley
Implemented default command options
1454
1534.7.156 by Aaron Bentley
PEP8 fixes
1455
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1456
class BadConversionTarget(BzrError):
1457
1458
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1459
1460
    def __init__(self, problem, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1461
        BzrError.__init__(self)
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1462
        self.problem = problem
1463
        self.format = format
1464
1465
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1466
class NoDiff(BzrError):
1467
1468
    _fmt = "Diff is not installed on this machine: %(msg)s"
1711.2.56 by John Arbash Meinel
Raise NoDiff if 'diff' not present.
1469
1470
    def __init__(self, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1471
        BzrError.__init__(self, msg=msg)
1472
1473
1474
class NoDiff3(BzrError):
1475
1476
    _fmt = "Diff3 is not installed on this machine."
1477
1478
1479
class ExistingLimbo(BzrError):
1480
1481
    _fmt = """This tree contains left-over files from a failed operation.
1482
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1483
    keep, and delete it when you are done."""
1484
    
1485
    def __init__(self, limbo_dir):
1486
       BzrError.__init__(self)
1487
       self.limbo_dir = limbo_dir
1488
1489
1490
class ImmortalLimbo(BzrError):
1491
1492
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
1493
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1494
    keep, and delete it when you are done."""
1495
1496
    def __init__(self, limbo_dir):
1497
       BzrError.__init__(self)
1498
       self.limbo_dir = limbo_dir
1499
1500
1501
class OutOfDateTree(BzrError):
1502
1503
    _fmt = "Working tree is out of date, please run 'bzr update'."
1508.1.25 by Robert Collins
Update per review comments.
1504
1505
    def __init__(self, tree):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1506
        BzrError.__init__(self)
1508.1.25 by Robert Collins
Update per review comments.
1507
        self.tree = tree
1534.7.196 by Aaron Bentley
Switched to Rio format for merge-modified list
1508
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
1509
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1510
class MergeModifiedFormatError(BzrError):
1511
1512
    _fmt = "Error in merge modified format"
1513
1514
1515
class ConflictFormatError(BzrError):
1516
1517
    _fmt = "Format error in conflict listings"
1518
1519
1520
class CorruptRepository(BzrError):
1521
1522
    _fmt = """An error has been detected in the repository %(repo_path)s.
1570.1.13 by Robert Collins
Check for incorrect revision parentage in the weave during revision access.
1523
Please run bzr reconcile on this repository."""
1524
1525
    def __init__(self, repo):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1526
        BzrError.__init__(self)
1570.1.13 by Robert Collins
Check for incorrect revision parentage in the weave during revision access.
1527
        self.repo_path = repo.bzrdir.root_transport.base
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1528
1529
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1530
class UpgradeRequired(BzrError):
1531
1532
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1533
1534
    def __init__(self, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1535
        BzrError.__init__(self)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1536
        self.path = path
1537
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
1538
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1539
class LocalRequiresBoundBranch(BzrError):
1540
1541
    _fmt = "Cannot perform local-only commits on unbound branches."
1542
1543
1544
class MissingProgressBarFinish(BzrError):
1545
1546
    _fmt = "A nested progress bar was not 'finished' correctly."
1547
1548
1549
class InvalidProgressBarType(BzrError):
1550
1551
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1843.3.7 by John Arbash Meinel
new env var 'BZR_PROGRESS_BAR' to select the exact progress type
1552
Select one of: %(valid_types)s"""
1553
1554
    def __init__(self, bar_type, valid_types):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1555
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1556
1557
1558
class UnsupportedOperation(BzrError):
1559
1560
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
2067.3.2 by Martin Pool
Error cleanup review comments:
1561
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
1562
    def __init__(self, method, method_self):
1563
        self.method = method
1564
        self.mname = method.__name__
1565
        self.tname = type(method_self).__name__
1558.15.1 by Aaron Bentley
Add text_file function
1566
1567
2150.2.2 by Robert Collins
Change the commit builder selected-revision-id test to use a unicode revision id where possible, leading to stricter testing of the hypothetical unicode revision id support in bzr.
1568
class CannotSetRevisionId(UnsupportedOperation):
1569
    """Raised when a commit is attempting to set a revision id but cant."""
1570
1571
1572
class NonAsciiRevisionId(UnsupportedOperation):
1573
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
1574
1575
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1576
class BinaryFile(BzrError):
1577
    
1578
    _fmt = "File is binary but should be text."
1579
1580
1581
class IllegalPath(BzrError):
1582
1583
    _fmt = "The path %(path)s is not permitted on this platform"
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
1584
1585
    def __init__(self, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1586
        BzrError.__init__(self)
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
1587
        self.path = path
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
1588
1589
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1590
class TestamentMismatch(BzrError):
1591
1592
    _fmt = """Testament did not match expected value.  
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
1593
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1594
       {%(measured)s}"""
1595
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
1596
    def __init__(self, revision_id, expected, measured):
1597
        self.revision_id = revision_id
1598
        self.expected = expected
1599
        self.measured = measured
1185.82.131 by Aaron Bentley
Move BadBundle error (and subclasses) to errors.py
1600
1601
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1602
class NotABundle(BzrError):
1603
    
1604
    _fmt = "Not a bzr revision-bundle: %(text)r"
1185.82.142 by Aaron Bentley
Update for review comments
1605
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
1606
    def __init__(self, text):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1607
        BzrError.__init__(self)
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
1608
        self.text = text
1609
1610
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1611
class BadBundle(BzrError): 
1612
    
1613
    _fmt = "Bad bzr revision-bundle: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
1614
1615
    def __init__(self, text):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1616
        BzrError.__init__(self)
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
1617
        self.text = text
1618
1619
1620
class MalformedHeader(BadBundle): 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1621
    
1622
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
1623
1624
1625
class MalformedPatches(BadBundle): 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1626
    
1627
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
1628
1629
1630
class MalformedFooter(BadBundle): 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1631
    
1632
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
1633
1910.7.17 by Andrew Bennetts
Various cosmetic changes.
1634
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
1635
class UnsupportedEOLMarker(BadBundle):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1636
    
1637
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
1638
1639
    def __init__(self):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1640
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1641
        # but for this there is not
1642
        BzrError.__init__(self)
1643
1644
1645
class IncompatibleBundleFormat(BzrError):
1646
    
1647
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
1648
1649
    def __init__(self, bundle_format, other):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1650
        BzrError.__init__(self)
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
1651
        self.bundle_format = bundle_format
1652
        self.other = other
1653
1654
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1655
class BadInventoryFormat(BzrError):
1656
    
1657
    _fmt = "Root class for inventory serialization errors"
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
1658
1659
1660
class UnexpectedInventoryFormat(BadInventoryFormat):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1661
1662
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
1663
1664
    def __init__(self, msg):
1665
        BadInventoryFormat.__init__(self, msg=msg)
1910.2.47 by Aaron Bentley
Merge bzr.dev
1666
1667
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1668
class NoSmartMedium(BzrError):
1669
1670
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2018.2.3 by Andrew Bennetts
Starting factoring out the smart server client "medium" from the protocol.
1671
1672
    def __init__(self, transport):
1673
        self.transport = transport
1674
1675
1910.19.2 by Andrew Bennetts
Add a new method ``Transport.get_smart_client()``. This is provided to allow
1676
class NoSmartServer(NotBranchError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1677
1678
    _fmt = "No smart server available at %(url)s"
1910.19.2 by Andrew Bennetts
Add a new method ``Transport.get_smart_client()``. This is provided to allow
1679
1680
    def __init__(self, url):
1681
        self.url = url
1682
1683
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1684
class UnknownSSH(BzrError):
1685
1686
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1951.1.8 by Andrew Bennetts
Make _get_ssh_vendor return the vendor object, rather than just a string.
1687
1688
    def __init__(self, vendor):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1689
        BzrError.__init__(self)
1951.1.8 by Andrew Bennetts
Make _get_ssh_vendor return the vendor object, rather than just a string.
1690
        self.vendor = vendor
1691
1908.5.16 by Robert Collins
Merge bzr.dev to resolve conflicts for merging.
1692
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1693
class GhostRevisionUnusableHere(BzrError):
1694
1695
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
1696
1697
    def __init__(self, revision_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1698
        BzrError.__init__(self)
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
1699
        self.revision_id = revision_id
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
1700
1701
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1702
class IllegalUseOfScopeReplacer(BzrError):
1703
1704
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
1705
2067.3.2 by Martin Pool
Error cleanup review comments:
1706
    internal_error = True
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
1707
1708
    def __init__(self, name, msg, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1709
        BzrError.__init__(self)
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
1710
        self.name = name
1711
        self.msg = msg
1712
        if extra:
1713
            self.extra = ': ' + str(extra)
1714
        else:
1715
            self.extra = ''
1716
1996.1.18 by John Arbash Meinel
Add more structured error handling
1717
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1718
class InvalidImportLine(BzrError):
1719
1720
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
1996.1.18 by John Arbash Meinel
Add more structured error handling
1721
2067.3.2 by Martin Pool
Error cleanup review comments:
1722
    internal_error = True
1996.1.18 by John Arbash Meinel
Add more structured error handling
1723
1724
    def __init__(self, text, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1725
        BzrError.__init__(self)
1996.1.18 by John Arbash Meinel
Add more structured error handling
1726
        self.text = text
1727
        self.msg = msg
1728
1729
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1730
class ImportNameCollision(BzrError):
1731
1732
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
1996.1.18 by John Arbash Meinel
Add more structured error handling
1733
2067.3.2 by Martin Pool
Error cleanup review comments:
1734
    internal_error = True
1996.1.18 by John Arbash Meinel
Add more structured error handling
1735
1736
    def __init__(self, name):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1737
        BzrError.__init__(self)
1996.1.18 by John Arbash Meinel
Add more structured error handling
1738
        self.name = name