/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.152 by Martin Pool
(broken) merge aaron's workingtree format changes
1
# Copyright (C) 2005, 2006, 2007 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.12 by Marius Kruger
* Fix errors.py import order
21
from bzrlib import (
22
    osutils,
23
    symbol_versioning,
24
    )
25
from bzrlib.patches import (
26
    MalformedHunkHeader,
27
    MalformedLine,
28
    MalformedPatchHeader,
29
    PatchConflict,
30
    PatchSyntax,
31
    )
1185.82.128 by Aaron Bentley
Provide errors from bzrlib.patches in bzrlib.errors
32
33
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
34
# TODO: is there any value in providing the .args field used by standard
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
35
# python exceptions?   A list of values with no names seems less useful 
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
36
# to me.
37
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
38
# TODO: Perhaps convert the exception to a string at the moment it's 
1185.16.63 by Martin Pool
- more error conversion
39
# constructed to make sure it will succeed.  But that says nothing about
40
# exceptions that are never raised.
41
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
42
# TODO: selftest assertRaises should probably also check that every error
43
# raised can be formatted as a string successfully, and without giving
44
# 'unprintable'.
1662.1.12 by Martin Pool
Translate unknown sftp errors to PathError, no NoSuchFile
45
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
46
2713.2.1 by Martin Pool
Return exitcode 4 if an internal error occurs
47
# return codes from the bzr program
48
EXIT_ERROR = 3
49
EXIT_INTERNAL_ERROR = 4
50
51
1 by mbp at sourcefrog
import from baz patch-364
52
class BzrError(StandardError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
53
    """
54
    Base class for errors raised by bzrlib.
55
2535.1.1 by Adeodato Simó
Fix BzrError docstring: internal_error defaults to False, not to True.
56
    :cvar internal_error: if True this was probably caused by a bzr bug and
57
    should be displayed with a traceback; if False (or absent) this was
2067.3.2 by Martin Pool
Error cleanup review comments:
58
    probably a user or environment error and they don't need the gory details.
59
    (That can be overridden by -Derror on the command line.)
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
60
2067.3.2 by Martin Pool
Error cleanup review comments:
61
    :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.
62
    by the instance's dict.
63
    """
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
64
    
2067.3.2 by Martin Pool
Error cleanup review comments:
65
    internal_error = False
1685.2.1 by Brian M. Carlson
Add a workaround for usage of the args attribute in exceptions.
66
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
67
    def __init__(self, msg=None, **kwds):
68
        """Construct a new BzrError.
69
70
        There are two alternative forms for constructing these objects.
71
        Either a preformatted string may be passed, or a set of named
72
        arguments can be given.  The first is for generic "user" errors which
73
        are not intended to be caught and so do not need a specific subclass.
74
        The second case is for use with subclasses that provide a _fmt format
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
75
        string to print the arguments.  
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
76
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
77
        Keyword arguments are taken as parameters to the error, which can 
78
        be inserted into the format string template.  It's recommended 
79
        that subclasses override the __init__ method to require specific 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
80
        parameters.
81
2067.3.2 by Martin Pool
Error cleanup review comments:
82
        :param msg: If given, this is the literal complete text for the error,
83
        not subject to expansion.
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
84
        """
85
        StandardError.__init__(self)
86
        if msg is not None:
2067.3.4 by Martin Pool
Error deprecations will come in for 0.13
87
            # I was going to deprecate this, but it actually turns out to be
88
            # quite handy - mbp 20061103.
2067.3.2 by Martin Pool
Error cleanup review comments:
89
            self._preformatted_string = msg
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
90
        else:
2067.3.2 by Martin Pool
Error cleanup review comments:
91
            self._preformatted_string = None
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
92
            for key, value in kwds.items():
93
                setattr(self, key, value)
94
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
95
    def __str__(self):
2067.3.2 by Martin Pool
Error cleanup review comments:
96
        s = getattr(self, '_preformatted_string', None)
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
97
        if s is not None:
98
            # contains a preformatted message; must be cast to plain str
99
            return str(s)
100
        try:
2067.3.2 by Martin Pool
Error cleanup review comments:
101
            fmt = self._get_format_string()
102
            if fmt:
103
                s = fmt % self.__dict__
104
                # __str__() should always return a 'str' object
105
                # never a 'unicode' object.
106
                if isinstance(s, unicode):
107
                    return s.encode('utf8')
108
                return s
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
109
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
2456.1.1 by Robert Collins
Fix the 'Unprintable error' message display to use the repr of the
110
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
111
                % (self.__class__.__name__,
112
                   self.__dict__,
113
                   getattr(self, '_fmt', None),
2456.1.1 by Robert Collins
Fix the 'Unprintable error' message display to use the repr of the
114
                   e)
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
115
2067.3.2 by Martin Pool
Error cleanup review comments:
116
    def _get_format_string(self):
117
        """Return format string for this exception or None"""
118
        fmt = getattr(self, '_fmt', None)
119
        if fmt is not None:
120
            return fmt
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
121
        fmt = getattr(self, '__doc__', None)
2067.3.2 by Martin Pool
Error cleanup review comments:
122
        if fmt is not None:
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
123
            symbol_versioning.warn("%s uses its docstring as a format, "
124
                    "it should use _fmt instead" % self.__class__.__name__,
125
                    DeprecationWarning)
126
            return fmt
127
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
128
            % (self.__class__.__name__,
129
               self.__dict__,
130
               getattr(self, '_fmt', None),
131
               )
2067.3.2 by Martin Pool
Error cleanup review comments:
132
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
133
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
134
class BzrNewError(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
135
    """Deprecated error base class."""
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
136
    # base classes should override the docstring with their human-
137
    # readable explanation
138
1685.2.1 by Brian M. Carlson
Add a workaround for usage of the args attribute in exceptions.
139
    def __init__(self, *args, **kwds):
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
140
        # XXX: Use the underlying BzrError to always generate the args
141
        # attribute if it doesn't exist.  We can't use super here, because
142
        # exceptions are old-style classes in python2.4 (but new in 2.5).
143
        # --bmc, 20060426
2067.3.4 by Martin Pool
Error deprecations will come in for 0.13
144
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
145
             'please convert %s to use BzrError instead'
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
146
             % self.__class__.__name__,
147
             DeprecationWarning,
148
             stacklevel=2)
1685.2.2 by Brian M. Carlson
Change the BzrNewError super invocation to a direct call, so it works with 2.4.
149
        BzrError.__init__(self, *args)
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
150
        for key, value in kwds.items():
151
            setattr(self, key, value)
152
153
    def __str__(self):
154
        try:
1948.1.6 by John Arbash Meinel
Make BzrNewError always return a str object
155
            # __str__() should always return a 'str' object
156
            # never a 'unicode' object.
157
            s = self.__doc__ % self.__dict__
158
            if isinstance(s, unicode):
159
                return s.encode('utf8')
160
            return s
1910.12.1 by Andrew Bennetts
Catch TypeError in BzrNewError.__str__, and print more information if an exception happens in that.
161
        except (TypeError, NameError, ValueError, KeyError), e:
2456.1.1 by Robert Collins
Fix the 'Unprintable error' message display to use the repr of the
162
            return 'Unprintable exception %s(%r): %r' \
1910.12.1 by Andrew Bennetts
Catch TypeError in BzrNewError.__str__, and print more information if an exception happens in that.
163
                % (self.__class__.__name__,
2456.1.1 by Robert Collins
Fix the 'Unprintable error' message display to use the repr of the
164
                   self.__dict__, e)
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
165
166
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
167
class AlreadyBuilding(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
168
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
169
    _fmt = "The tree builder is already building a tree."
170
171
172
class BzrCheckError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
173
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
174
    _fmt = "Internal check failed: %(message)s"
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
175
2067.3.2 by Martin Pool
Error cleanup review comments:
176
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
177
1185.16.63 by Martin Pool
- more error conversion
178
    def __init__(self, message):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
179
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
180
        self.message = message
181
182
2018.9.1 by Andrew Bennetts
Merge from bzr.dev.
183
class DisabledMethod(BzrError):
184
185
    _fmt = "The smart server method '%(class_name)s' is disabled."
186
187
    internal_error = True
2018.5.24 by Andrew Bennetts
Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)
188
189
    def __init__(self, class_name):
2018.9.1 by Andrew Bennetts
Merge from bzr.dev.
190
        BzrError.__init__(self)
2018.5.24 by Andrew Bennetts
Setting NO_SMART_VFS in environment will disable VFS methods in the smart server. (Robert Collins, John Arbash Meinel, Andrew Bennetts)
191
        self.class_name = class_name
192
193
2550.2.3 by Robert Collins
Add require_api API.
194
class IncompatibleAPI(BzrError):
195
196
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
197
        'It supports versions "%(minimum)s" to "%(current)s".'
198
199
    def __init__(self, api, wanted, minimum, current):
200
        self.api = api
201
        self.wanted = wanted
202
        self.minimum = minimum
203
        self.current = current
204
205
2634.1.1 by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch.
206
class InProcessTransport(BzrError):
207
208
    _fmt = "The transport '%(transport)s' is only accessible within this " \
209
        "process."
210
211
    def __init__(self, transport):
212
        self.transport = transport
213
214
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
215
class InvalidEntryName(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
216
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
217
    _fmt = "Invalid entry name: %(name)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
218
2067.3.2 by Martin Pool
Error cleanup review comments:
219
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
220
1185.16.63 by Martin Pool
- more error conversion
221
    def __init__(self, name):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
222
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
223
        self.name = name
224
225
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
226
class InvalidRevisionNumber(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
227
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
228
    _fmt = "Invalid revision number %(revno)s"
229
1185.16.63 by Martin Pool
- more error conversion
230
    def __init__(self, revno):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
231
        BzrError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
232
        self.revno = revno
233
234
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
235
class InvalidRevisionId(BzrError):
236
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
237
    _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.
238
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
239
    def __init__(self, revision_id, branch):
1668.5.1 by Olaf Conradi
Fix bug in knits when raising InvalidRevisionId without the required
240
        # branch can be any string or object with __str__ defined
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
241
        BzrError.__init__(self)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
242
        self.revision_id = revision_id
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
243
        self.branch = branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
244
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
245
class ReservedId(BzrError):
2229.2.3 by Aaron Bentley
change reserved_id to is_reserved_id, add check_not_reserved for DRY
246
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
247
    _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
248
2229.2.1 by Aaron Bentley
Reject reserved ids in versiondfile, tree, branch and repository
249
    def __init__(self, revision_id):
250
        self.revision_id = revision_id
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
251
2432.1.4 by Robert Collins
Add an explicit error for missing help topics.
252
253
class NoHelpTopic(BzrError):
254
255
    _fmt = ("No help could be found for '%(topic)s'. "
256
        "Please use 'bzr help topics' to obtain a list of topics.")
257
258
    def __init__(self, topic):
259
        self.topic = topic
260
261
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
262
class NoSuchId(BzrError):
263
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
264
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
265
    
1988.2.1 by Robert Collins
WorkingTree has a new api ``unversion`` which allow the unversioning of
266
    def __init__(self, tree, file_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
267
        BzrError.__init__(self)
1988.2.1 by Robert Collins
WorkingTree has a new api ``unversion`` which allow the unversioning of
268
        self.file_id = file_id
269
        self.tree = tree
270
271
2708.1.11 by Aaron Bentley
Test and tweak error handling
272
class NoSuchIdInRepository(NoSuchId):
273
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
274
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
275
            ' %(repository)r')
2708.1.11 by Aaron Bentley
Test and tweak error handling
276
277
    def __init__(self, repository, file_id):
278
        BzrError.__init__(self, repository=repository, file_id=file_id)
279
280
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
281
class InventoryModified(BzrError):
282
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
283
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
284
            " so a clean inventory cannot be read without data loss.")
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
285
286
    internal_error = True
287
288
    def __init__(self, tree):
289
        self.tree = tree
290
291
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
292
class NoWorkingTree(BzrError):
293
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
294
    _fmt = 'No WorkingTree exists for "%(base)s".'
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
295
    
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
296
    def __init__(self, base):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
297
        BzrError.__init__(self)
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
298
        self.base = base
1506 by Robert Collins
Merge Johns current integration work.
299
300
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
301
class NotBuilding(BzrError):
302
303
    _fmt = "Not currently building a tree."
304
305
306
class NotLocalUrl(BzrError):
307
308
    _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
309
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
310
    def __init__(self, url):
311
        self.url = url
312
313
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
314
class WorkingTreeAlreadyPopulated(BzrError):
315
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
316
    _fmt = 'Working tree already populated in "%(base)s"'
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
317
318
    internal_error = True
319
320
    def __init__(self, base):
321
        self.base = base
322
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
323
class BzrCommandError(BzrError):
1740.5.6 by Martin Pool
Clean up many exception classes.
324
    """Error from user command"""
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
325
2067.3.2 by Martin Pool
Error cleanup review comments:
326
    internal_error = False
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
327
328
    # Error from malformed user command; please avoid raising this as a
329
    # generic exception not caused by user input.
1185.54.18 by Aaron Bentley
Noted difference of opinion wrt BzrCommandError
330
    #
331
    # I think it's a waste of effort to differentiate between errors that
332
    # are not intended to be caught anyway.  UI code need not subclass
333
    # BzrCommandError, and non-UI code should not throw a subclass of
334
    # BzrCommandError.  ADHB 20051211
1740.5.6 by Martin Pool
Clean up many exception classes.
335
    def __init__(self, msg):
1948.1.5 by John Arbash Meinel
Make sure BzrCommandError can handle unicode arguments
336
        # Object.__str__() must return a real string
337
        # returning a Unicode string is a python error.
338
        if isinstance(msg, unicode):
339
            self.msg = msg.encode('utf8')
340
        else:
341
            self.msg = msg
1740.5.6 by Martin Pool
Clean up many exception classes.
342
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
343
    def __str__(self):
1740.5.6 by Martin Pool
Clean up many exception classes.
344
        return self.msg
345
346
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
347
class NotWriteLocked(BzrError):
348
349
    _fmt = """%(not_locked)r is not write locked but needs to be."""
350
351
    def __init__(self, not_locked):
352
        self.not_locked = not_locked
353
354
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
355
class BzrOptionError(BzrCommandError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
356
357
    _fmt = "Error in command line options"
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
358
2221.4.1 by Aaron Bentley
Get registry options working
359
2592.1.7 by Robert Collins
A validate that goes boom.
360
class BadIndexFormatSignature(BzrError):
361
362
    _fmt = "%(value)s is not an index of type %(_type)s."
363
364
    def __init__(self, value, _type):
365
        BzrError.__init__(self)
366
        self.value = value
367
        self._type = _type
368
369
2592.1.11 by Robert Collins
Detect truncated indices.
370
class BadIndexData(BzrError):
371
372
    _fmt = "Error in data for index %(value)s."
373
374
    def __init__(self, value):
375
        BzrError.__init__(self)
376
        self.value = value
377
378
2592.1.15 by Robert Collins
Detect duplicate key insertion.
379
class BadIndexDuplicateKey(BzrError):
380
381
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
382
383
    def __init__(self, key, index):
384
        BzrError.__init__(self)
385
        self.key = key
386
        self.index = index
387
388
2592.1.12 by Robert Collins
Handle basic node adds.
389
class BadIndexKey(BzrError):
390
391
    _fmt = "The key '%(key)s' is not a valid key."
392
393
    def __init__(self, key):
394
        BzrError.__init__(self)
395
        self.key = key
396
397
2592.1.10 by Robert Collins
Make validate detect node reference parsing errors.
398
class BadIndexOptions(BzrError):
399
400
    _fmt = "Could not parse options for index %(value)s."
401
402
    def __init__(self, value):
403
        BzrError.__init__(self)
404
        self.value = value
405
406
2592.1.12 by Robert Collins
Handle basic node adds.
407
class BadIndexValue(BzrError):
408
409
    _fmt = "The value '%(value)s' is not a valid value."
410
411
    def __init__(self, value):
412
        BzrError.__init__(self)
413
        self.value = value
414
415
2221.4.6 by Aaron Bentley
Improve text and naming
416
class BadOptionValue(BzrError):
2221.4.1 by Aaron Bentley
Get registry options working
417
2221.4.6 by Aaron Bentley
Improve text and naming
418
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
2221.4.1 by Aaron Bentley
Get registry options working
419
420
    def __init__(self, name, value):
421
        BzrError.__init__(self, name=name, value=value)
422
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
423
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
424
class StrictCommitFailed(BzrError):
425
426
    _fmt = "Commit refused because there are unknown files in the tree"
1 by mbp at sourcefrog
import from baz patch-364
427
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
428
1662.1.12 by Martin Pool
Translate unknown sftp errors to PathError, no NoSuchFile
429
# XXX: Should be unified with TransportError; they seem to represent the
430
# same thing
2052.6.1 by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use.
431
# RBC 20060929: I think that unifiying with TransportError would be a mistake
432
# - this is finer than a TransportError - and more useful as such. It 
433
# differentiates between 'transport has failed' and 'operation on a transport
434
# has failed.'
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
435
class PathError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
436
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
437
    _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.
438
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
439
    def __init__(self, path, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
440
        BzrError.__init__(self)
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
441
        self.path = path
1908.4.11 by John Arbash Meinel
reverting changes to errors.py and local transport.
442
        if extra:
443
            self.extra = ': ' + str(extra)
444
        else:
445
            self.extra = ''
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
446
447
448
class NoSuchFile(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
449
450
    _fmt = "No such file: %(path)r%(extra)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
451
452
453
class FileExists(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
454
455
    _fmt = "File exists: %(path)r%(extra)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
456
457
2220.1.11 by Marius Kruger
* bzrlib/errors.py
458
class RenameFailedFilesExist(BzrError):
459
    """Used when renaming and both source and dest exist."""
460
2220.1.12 by Marius Kruger
* Fix errors.py import order
461
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
462
            "%(extra)s")
2220.1.11 by Marius Kruger
* bzrlib/errors.py
463
464
    def __init__(self, source, dest, extra=None):
2206.1.5 by Marius Kruger
* errors
465
        BzrError.__init__(self)
2220.1.11 by Marius Kruger
* bzrlib/errors.py
466
        self.source = str(source)
467
        self.dest = str(dest)
2206.1.5 by Marius Kruger
* errors
468
        if extra:
2220.1.11 by Marius Kruger
* bzrlib/errors.py
469
            self.extra = ' ' + str(extra)
2206.1.5 by Marius Kruger
* errors
470
        else:
471
            self.extra = ''
472
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
473
2206.1.4 by Marius Kruger
Improved WorkingTree.move excptions. (as requested)
474
class NotADirectory(PathError):
475
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
476
    _fmt = '"%(path)s" is not a directory %(extra)s'
2206.1.4 by Marius Kruger
Improved WorkingTree.move excptions. (as requested)
477
478
479
class NotInWorkingDirectory(PathError):
480
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
481
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
2206.1.4 by Marius Kruger
Improved WorkingTree.move excptions. (as requested)
482
483
1553.5.10 by Martin Pool
New DirectoryNotEmpty exception, and raise this from local and memory
484
class DirectoryNotEmpty(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
485
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
486
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
1553.5.10 by Martin Pool
New DirectoryNotEmpty exception, and raise this from local and memory
487
488
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
489
class ReadingCompleted(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
490
    
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
491
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
492
            "called upon it - the request has been completed and no more "
493
            "data may be read.")
494
495
    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.
496
2018.2.4 by Robert Collins
separate out the client medium from the client encoding protocol for the smart server.
497
    def __init__(self, request):
498
        self.request = request
499
500
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
501
class ResourceBusy(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
502
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
503
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
1558.10.1 by Aaron Bentley
Handle lockdirs over NFS properly
504
505
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
506
class PermissionDenied(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
507
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
508
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
509
510
1185.85.76 by John Arbash Meinel
Adding an InvalidURL so transports can report they expect utf-8 quoted paths. Updated tests
511
class InvalidURL(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
512
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
513
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
1185.85.76 by John Arbash Meinel
Adding an InvalidURL so transports can report they expect utf-8 quoted paths. Updated tests
514
515
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
516
class InvalidURLJoin(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
517
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
518
    _fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
519
520
    def __init__(self, msg, base, args):
521
        PathError.__init__(self, base, msg)
2027.2.2 by Marien Zwart
Fixes for python 2.5.
522
        self.args = [base] + list(args)
1685.1.55 by John Arbash Meinel
Adding bzrlib.urlutils.join() to handle joining URLs
523
524
2245.1.3 by Robert Collins
Add install_hook to the BranchHooks class as the official means for installing a hook.
525
class UnknownHook(BzrError):
526
527
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
528
529
    def __init__(self, hook_type, hook_name):
530
        BzrError.__init__(self)
531
        self.type = hook_type
532
        self.hook = hook_name
533
534
1843.1.1 by John Arbash Meinel
Update get_transport to raise a nicer error which includes dependency info
535
class UnsupportedProtocol(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
536
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
537
    _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
538
539
    def __init__(self, url, extra):
540
        PathError.__init__(self, url, extra=extra)
541
542
2052.6.1 by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use.
543
class ReadError(PathError):
2052.6.2 by Robert Collins
Merge bzr.dev.
544
    
545
    _fmt = """Error reading from %(path)r."""
2052.6.1 by Robert Collins
``Transport.get`` has had its interface made more clear for ease of use.
546
547
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
548
class ShortReadvError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
549
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
550
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
551
            ' at %(offset)s for "%(path)s"%(extra)s')
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
552
2067.3.2 by Martin Pool
Error cleanup review comments:
553
    internal_error = True
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
554
2001.3.3 by John Arbash Meinel
review feedback: add the actual count written to ShortReadvError
555
    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
556
        PathError.__init__(self, path, extra=extra)
557
        self.offset = offset
558
        self.length = length
2001.3.3 by John Arbash Meinel
review feedback: add the actual count written to ShortReadvError
559
        self.actual = actual
2001.3.2 by John Arbash Meinel
Force all transports to raise ShortReadvError if they can
560
561
2485.8.18 by Vincent Ladeuil
PathNotChild inherits from PathError, not BzrError.
562
class PathNotChild(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
563
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
564
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
1740.5.6 by Martin Pool
Clean up many exception classes.
565
2067.3.2 by Martin Pool
Error cleanup review comments:
566
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
567
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
568
    def __init__(self, path, base, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
569
        BzrError.__init__(self)
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
570
        self.path = path
571
        self.base = base
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
572
        if extra:
573
            self.extra = ': ' + str(extra)
574
        else:
575
            self.extra = ''
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
576
577
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
578
class InvalidNormalization(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
579
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
580
    _fmt = 'Path "%(path)s" is not unicode normalized'
1830.3.5 by John Arbash Meinel
make_entry refuses to create non-normalized entries.
581
582
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
583
# TODO: This is given a URL; we try to unescape it but doing that from inside
584
# the exception object is a bit undesirable.
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
585
# 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.
586
class NotBranchError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
587
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
588
    _fmt = 'Not a branch: "%(path)s".'
1685.1.60 by Martin Pool
[broken] NotBranchError should unescape the url if possible
589
590
    def __init__(self, path):
591
       import bzrlib.urlutils as urlutils
1908.4.11 by John Arbash Meinel
reverting changes to errors.py and local transport.
592
       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.
593
594
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
595
class NoSubmitBranch(PathError):
596
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
597
    _fmt = 'No submit branch available for branch "%(path)s"'
1551.10.32 by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs
598
599
    def __init__(self, branch):
600
       import bzrlib.urlutils as urlutils
601
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
602
603
1654.1.4 by Robert Collins
Teach `bzr init` how to init at the root of a repository.
604
class AlreadyBranchError(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
605
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
606
    _fmt = 'Already a branch: "%(path)s".'
1662.1.19 by Martin Pool
Better error message when initting existing tree
607
608
609
class BranchExistsWithoutWorkingTree(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
610
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
611
    _fmt = 'Directory contains a branch, but no working tree \
612
(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
613
573 by Martin Pool
- new exception NotBranchError
614
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.
615
class AtomicFileAlreadyClosed(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
616
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
617
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
618
            ' "%(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.
619
620
    def __init__(self, path, function):
621
        PathError.__init__(self, path=path, extra=None)
622
        self.function = function
623
624
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
625
class InaccessibleParent(PathError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
626
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
627
    _fmt = ('Parent not accessible given base "%(base)s" and'
628
            ' relative path "%(path)s"')
1864.7.2 by John Arbash Meinel
Test that we copy the parent across properly (if it is available)
629
630
    def __init__(self, path, base):
631
        PathError.__init__(self, path)
632
        self.base = base
633
634
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
635
class NoRepositoryPresent(BzrError):
636
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
637
    _fmt = 'No repository present: "%(path)s"'
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
638
    def __init__(self, bzrdir):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
639
        BzrError.__init__(self)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
640
        self.path = bzrdir.transport.clone('..').base
641
642
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
643
class FileInWrongBranch(BzrError):
644
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
645
    _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.
646
1185.35.32 by Aaron Bentley
Fixed handling of files in mixed branches
647
    def __init__(self, branch, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
648
        BzrError.__init__(self)
1185.35.32 by Aaron Bentley
Fixed handling of files in mixed branches
649
        self.branch = branch
650
        self.branch_base = branch.base
651
        self.path = path
652
653
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
654
class UnsupportedFormatError(BzrError):
2379.4.1 by John Arbash Meinel
(John Arbash Meinel) Make it clearer what to do if you have a (very) old branch.
655
656
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
657
658
659
class UnknownFormatError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
660
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
661
    _fmt = "Unknown branch format: %(format)r"
662
663
664
class IncompatibleFormat(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
665
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
666
    _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.
667
668
    def __init__(self, format, bzrdir_format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
669
        BzrError.__init__(self)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
670
        self.format = format
671
        self.bzrdir = bzrdir_format
672
673
2323.8.2 by Aaron Bentley
Give a nicer error on fetch when repos are in incompatible formats
674
class IncompatibleRepositories(BzrError):
675
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
676
    _fmt = "Repository %(target)s is not compatible with repository"\
677
        " %(source)s"
2323.8.2 by Aaron Bentley
Give a nicer error on fetch when repos are in incompatible formats
678
679
    def __init__(self, source, target):
680
        BzrError.__init__(self, target=target, source=source)
681
682
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
683
class IncompatibleRevision(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
684
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
685
    _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
686
687
    def __init__(self, repo_format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
688
        BzrError.__init__(self)
1910.2.60 by Aaron Bentley
Ensure that new-model revisions aren't installed into old-model repos
689
        self.repo_format = repo_format
690
691
2206.1.5 by Marius Kruger
* errors
692
class AlreadyVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
693
    """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
694
2745.3.1 by Daniel Watkins
Modified errors.py to quote paths just before full stops. Also added some full stops to error messages without them.
695
    _fmt = "%(context_info)s%(path)s is already versioned."
2206.1.5 by Marius Kruger
* errors
696
2206.1.7 by Marius Kruger
* errors
697
    def __init__(self, path, context_info=None):
2255.2.29 by Robert Collins
Change the error raised from Dirstate.add for an unversioned parent path to match the WorkingTree interface.
698
        """Construct a new AlreadyVersionedError.
2206.1.5 by Marius Kruger
* errors
699
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
700
        :param path: This is the path which is versioned,
2206.1.5 by Marius Kruger
* errors
701
        which should be in a user friendly form.
2206.1.7 by Marius Kruger
* errors
702
        :param context_info: If given, this is information about the context,
2206.1.5 by Marius Kruger
* errors
703
        which could explain why this is expected to not be versioned.
704
        """
705
        BzrError.__init__(self)
706
        self.path = path
2206.1.7 by Marius Kruger
* errors
707
        if context_info is None:
708
            self.context_info = ''
2206.1.5 by Marius Kruger
* errors
709
        else:
2206.1.7 by Marius Kruger
* errors
710
            self.context_info = context_info + ". "
2206.1.5 by Marius Kruger
* errors
711
712
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
713
class NotVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
714
    """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
715
2745.3.1 by Daniel Watkins
Modified errors.py to quote paths just before full stops. Also added some full stops to error messages without them.
716
    _fmt = "%(context_info)s%(path)s is not versioned."
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
717
2206.1.7 by Marius Kruger
* errors
718
    def __init__(self, path, context_info=None):
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
719
        """Construct a new NotVersionedError.
720
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
721
        :param path: This is the path which is not versioned,
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
722
        which should be in a user friendly form.
2206.1.7 by Marius Kruger
* errors
723
        :param context_info: If given, this is information about the context,
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
724
        which could explain why this is expected to be versioned.
725
        """
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
726
        BzrError.__init__(self)
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
727
        self.path = path
2206.1.7 by Marius Kruger
* errors
728
        if context_info is None:
729
            self.context_info = ''
2206.1.2 by Marius Kruger
* Made whitespace and puntuation improvements, as requested.
730
        else:
2206.1.7 by Marius Kruger
* errors
731
            self.context_info = context_info + ". "
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
732
733
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
734
class PathsNotVersionedError(BzrError):
2206.1.7 by Marius Kruger
* errors
735
    """Used when reporting several paths which are not versioned"""
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
736
737
    _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)
738
739
    def __init__(self, paths):
740
        from bzrlib.osutils import quotefn
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
741
        BzrError.__init__(self)
1658.1.9 by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619)
742
        self.paths = paths
743
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
744
745
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
746
class PathsDoNotExist(BzrError):
747
2206.1.5 by Marius Kruger
* errors
748
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
1662.1.14 by Martin Pool
(PathsDoNotExist) review style comments
749
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
750
    # used when reporting that paths are neither versioned nor in the working
751
    # tree
752
2206.1.5 by Marius Kruger
* errors
753
    def __init__(self, paths, extra=None):
1662.1.14 by Martin Pool
(PathsDoNotExist) review style comments
754
        # circular import
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
755
        from bzrlib.osutils import quotefn
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
756
        BzrError.__init__(self)
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
757
        self.paths = paths
758
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
2206.1.5 by Marius Kruger
* errors
759
        if extra:
760
            self.extra = ': ' + str(extra)
761
        else:
762
            self.extra = ''
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
763
764
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
765
class BadFileKindError(BzrError):
766
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
767
    _fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
768
769
    def __init__(self, filename, kind):
770
        BzrError.__init__(self, filename=filename, kind=kind)
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
771
772
773
class ForbiddenControlFileError(BzrError):
774
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
775
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
776
777
778
class LockError(BzrError):
779
2321.3.6 by Alexander Belchenko
LockError produce unprintable exception on Python 2.5 because it try to override StandardError.message attribute
780
    _fmt = "Lock error: %(msg)s"
2221.2.2 by Aaron Bentley
PEP8-correctness
781
2221.2.1 by Aaron Bentley
Make most lock errors internal
782
    internal_error = True
2067.3.2 by Martin Pool
Error cleanup review comments:
783
1185.16.63 by Martin Pool
- more error conversion
784
    # All exceptions from the lock/unlock functions should be from
785
    # this exception class.  They will be translated as necessary. The
786
    # original exception is available as e.original_error
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
787
    #
788
    # New code should prefer to raise specific subclasses
789
    def __init__(self, message):
2321.3.10 by Alexander Belchenko
Explanation about Python 2.5 and StandardError.message attribute
790
        # Python 2.5 uses a slot for StandardError.message,
791
        # so use a different variable name
792
        # so it is exposed in self.__dict__
2321.3.6 by Alexander Belchenko
LockError produce unprintable exception on Python 2.5 because it try to override StandardError.message attribute
793
        self.msg = message
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
794
795
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
796
class LockActive(LockError):
797
798
    _fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
799
800
    internal_error = False
801
802
    def __init__(self, lock_description):
803
        self.lock_description = lock_description
804
805
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
806
class CommitNotPossible(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
807
808
    _fmt = "A commit was attempted but we do not have a write lock open."
2067.3.2 by Martin Pool
Error cleanup review comments:
809
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
810
    def __init__(self):
811
        pass
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
812
813
814
class AlreadyCommitted(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
815
816
    _fmt = "A rollback was requested, but is not able to be accomplished."
2067.3.2 by Martin Pool
Error cleanup review comments:
817
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
818
    def __init__(self):
819
        pass
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
820
821
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
822
class ReadOnlyError(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
823
824
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
825
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
826
    # TODO: There should also be an error indicating that you need a write
827
    # lock and don't have any lock at all... mbp 20070226
828
1553.5.33 by Martin Pool
LockDir review comment fixes
829
    def __init__(self, obj):
830
        self.obj = obj
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
831
832
2353.3.3 by John Arbash Meinel
Define an explicit error when trying to grab a write lock on a readonly file.
833
class ReadOnlyLockError(LockError):
2353.3.10 by John Arbash Meinel
Cleanup errors, and change ReadOnlyLockError to pass around more details.
834
835
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
836
837
    def __init__(self, fname, msg):
2353.3.3 by John Arbash Meinel
Define an explicit error when trying to grab a write lock on a readonly file.
838
        LockError.__init__(self, '')
839
        self.fname = fname
2353.3.10 by John Arbash Meinel
Cleanup errors, and change ReadOnlyLockError to pass around more details.
840
        self.msg = msg
2353.3.3 by John Arbash Meinel
Define an explicit error when trying to grab a write lock on a readonly file.
841
842
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
843
class OutSideTransaction(BzrError):
844
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
845
    _fmt = ("A transaction related operation was attempted after"
846
            " the transaction finished.")
1594.2.21 by Robert Collins
Teach versioned files to prevent mutation after finishing.
847
848
1553.5.36 by Martin Pool
Clean up duplicate BranchNotLocked error and rename to ObjectNotLocked
849
class ObjectNotLocked(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
850
851
    _fmt = "%(obj)r is not locked"
1740.5.8 by Martin Pool
Review cleanups: better error reporting, put back report_exception.
852
1553.5.36 by Martin Pool
Clean up duplicate BranchNotLocked error and rename to ObjectNotLocked
853
    # this can indicate that any particular object is not locked; see also
854
    # LockNotHeld which means that a particular *lock* object is not held by
855
    # the caller -- perhaps they should be unified.
856
    def __init__(self, obj):
857
        self.obj = obj
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
858
859
860
class ReadOnlyObjectDirtiedError(ReadOnlyError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
861
862
    _fmt = "Cannot change object %(obj)r in read only transaction"
2067.3.2 by Martin Pool
Error cleanup review comments:
863
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
864
    def __init__(self, obj):
865
        self.obj = obj
866
867
868
class UnlockableTransport(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
869
870
    _fmt = "Cannot lock: transport is read only: %(transport)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
871
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
872
    def __init__(self, transport):
873
        self.transport = transport
874
875
876
class LockContention(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
877
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
878
    _fmt = 'Could not acquire lock "%(lock)s"'
2221.2.1 by Aaron Bentley
Make most lock errors internal
879
    # TODO: show full url for lock, combining the transport and relative
880
    # bits?
2221.2.2 by Aaron Bentley
PEP8-correctness
881
2221.2.1 by Aaron Bentley
Make most lock errors internal
882
    internal_error = False
2353.4.3 by John Arbash Meinel
Implement a 'ReadLock.temporary_write_lock()' to upgrade to a write-lock in-process.
883
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
884
    def __init__(self, lock):
885
        self.lock = lock
886
887
1553.5.23 by Martin Pool
Start LockDir.confirm method and LockBroken exception
888
class LockBroken(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
889
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
890
    _fmt = ("Lock was broken while still open: %(lock)s"
891
            " - check storage consistency!")
2221.2.2 by Aaron Bentley
PEP8-correctness
892
2221.2.1 by Aaron Bentley
Make most lock errors internal
893
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
894
1553.5.23 by Martin Pool
Start LockDir.confirm method and LockBroken exception
895
    def __init__(self, lock):
896
        self.lock = lock
897
898
1553.5.27 by Martin Pool
Confirm that only the intended holder of a lock was broken.
899
class LockBreakMismatch(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
900
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
901
    _fmt = ("Lock was released and re-acquired before being broken:"
902
            " %(lock)s: held by %(holder)r, wanted to break %(target)r")
2221.2.2 by Aaron Bentley
PEP8-correctness
903
2221.2.1 by Aaron Bentley
Make most lock errors internal
904
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
905
1553.5.27 by Martin Pool
Confirm that only the intended holder of a lock was broken.
906
    def __init__(self, lock, holder, target):
907
        self.lock = lock
908
        self.holder = holder
909
        self.target = target
910
911
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
912
class LockNotHeld(LockError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
913
914
    _fmt = "Lock not held: %(lock)s"
2221.2.2 by Aaron Bentley
PEP8-correctness
915
2221.2.1 by Aaron Bentley
Make most lock errors internal
916
    internal_error = False
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
917
1553.5.11 by Martin Pool
Change some lock and transaction related exceptions to BzrNewException style
918
    def __init__(self, lock):
919
        self.lock = lock
920
921
2279.7.1 by Andrew Bennetts
``LockableFiles.lock_write()`` now accepts a ``token`` keyword argument, so that
922
class TokenLockingNotSupported(LockError):
923
924
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
925
926
    internal_error = True
927
928
    def __init__(self, obj):
929
        self.obj = obj
930
931
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
932
class TokenMismatch(LockBroken):
2279.7.1 by Andrew Bennetts
``LockableFiles.lock_write()`` now accepts a ``token`` keyword argument, so that
933
934
    _fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
935
936
    internal_error = True
937
938
    def __init__(self, given_token, lock_token):
939
        self.given_token = given_token
940
        self.lock_token = lock_token
941
942
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
943
class PointlessCommit(BzrError):
944
945
    _fmt = "No changes to commit"
946
947
1551.15.9 by Aaron Bentley
Better error for selected-file commit of merges
948
class CannotCommitSelectedFileMerge(BzrError):
949
950
    _fmt = 'Selected-file commit of merges is not supported yet:'\
951
        ' files %(files_str)s'
952
953
    def __init__(self, files):
954
        files_str = ', '.join(files)
955
        BzrError.__init__(self, files=files, files_str=files_str)
956
957
2625.9.3 by Daniel Watkins
Added BadCommitMessageEncoding error.
958
class BadCommitMessageEncoding(BzrError):
959
960
    _fmt = 'The specified commit message contains characters unsupported by '\
961
        'the current encoding.'
962
963
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
964
class UpgradeReadonly(BzrError):
965
966
    _fmt = "Upgrade URL cannot work with readonly URLs."
967
968
969
class UpToDateFormat(BzrError):
970
971
    _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.
972
973
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
974
        BzrError.__init__(self)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
975
        self.format = format
976
977
1185.22.1 by Michael Ellerman
Implement strict commits with --strict flag.
978
class StrictCommitFailed(Exception):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
979
980
    _fmt = "Commit refused because there are unknowns in the tree."
981
982
983
class NoSuchRevision(BzrError):
984
2696.3.3 by Martin Pool
Start setting the default format to dirstate-tags
985
    _fmt = "%(branch)s has no revision %(revision)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
986
2067.3.2 by Martin Pool
Error cleanup review comments:
987
    internal_error = True
1740.5.6 by Martin Pool
Clean up many exception classes.
988
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
989
    def __init__(self, branch, revision):
2696.3.3 by Martin Pool
Start setting the default format to dirstate-tags
990
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
991
        BzrError.__init__(self, branch=branch, revision=revision)
992
993
2697.2.3 by Martin Pool
More append_revision cleanup; _synchronize_history optimization
994
# zero_ninetyone: this exception is no longer raised and should be removed
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
995
class NotLeftParentDescendant(BzrError):
996
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
997
    _fmt = ("Revision %(old_revision)s is not the left parent of"
998
            " %(new_revision)s, but branch %(branch_location)s expects this")
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
999
1000
    internal_error = True
1001
1002
    def __init__(self, branch, old_revision, new_revision):
2230.3.50 by Aaron Bentley
Fix broken error
1003
        BzrError.__init__(self, branch_location=branch.base,
1004
                          old_revision=old_revision,
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
1005
                          new_revision=new_revision)
1006
1007
2745.4.4 by Lukáš Lalinsky
- Make the description of --change more general
1008
class RangeInChangeOption(BzrError):
1009
1010
    _fmt = "Option --change does not accept revision ranges"
1011
1012
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1013
class NoSuchRevisionSpec(BzrError):
1014
1015
    _fmt = "No namespace registered for string: %(spec)r"
1948.4.25 by John Arbash Meinel
Check that invalid specs are properly handled
1016
1017
    def __init__(self, spec):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1018
        BzrError.__init__(self, spec=spec)
1019
1020
1908.11.1 by Robert Collins
Add a new method ``Tree.revision_tree`` which allows access to cached
1021
class NoSuchRevisionInTree(NoSuchRevision):
1908.11.5 by John Arbash Meinel
[merge] bzr.dev 2240
1022
    """When using Tree.revision_tree, and the revision is not accessible."""
1023
    
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1024
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1908.11.1 by Robert Collins
Add a new method ``Tree.revision_tree`` which allows access to cached
1025
1026
    def __init__(self, tree, revision_id):
1908.11.5 by John Arbash Meinel
[merge] bzr.dev 2240
1027
        BzrError.__init__(self)
1908.11.1 by Robert Collins
Add a new method ``Tree.revision_tree`` which allows access to cached
1028
        self.tree = tree
1029
        self.revision_id = revision_id
1030
1031
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1032
class InvalidRevisionSpec(BzrError):
1033
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1034
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1035
            " %(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
1036
1037
    def __init__(self, spec, branch, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1038
        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
1039
        if extra:
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
1040
            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
1041
        else:
1042
            self.extra = ''
1740.5.6 by Martin Pool
Clean up many exception classes.
1043
1044
1192 by Martin Pool
- clean up code for retrieving stored inventories
1045
class HistoryMissing(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1046
1047
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
1048
1049
2230.3.40 by Aaron Bentley
Rename strict_revision_history to append_revisions_only
1050
class AppendRevisionsOnlyViolation(BzrError):
2230.3.32 by Aaron Bentley
Implement strict history policy
1051
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
1052
    _fmt = ('Operation denied because it would change the main history,'
1053
           ' which is not permitted by the append_revisions_only setting on'
1054
           ' branch "%(location)s".')
2230.3.39 by Aaron Bentley
Improve history violation message
1055
1056
    def __init__(self, location):
1057
       import bzrlib.urlutils as urlutils
1058
       location = urlutils.unescape_for_display(location, 'ascii')
1059
       BzrError.__init__(self, location=location)
2230.3.32 by Aaron Bentley
Implement strict history policy
1060
1061
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1062
class DivergedBranches(BzrError):
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1063
1064
    _fmt = ("These branches have diverged."
1065
            " Use the merge command to reconcile them.")
1740.5.6 by Martin Pool
Clean up many exception classes.
1066
2067.3.2 by Martin Pool
Error cleanup review comments:
1067
    internal_error = False
1649.1.1 by Robert Collins
* 'pull' and 'push' now normalise the revision history, so that any two
1068
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
1069
    def __init__(self, branch1, branch2):
1070
        self.branch1 = branch1
1071
        self.branch2 = branch2
1072
1390 by Robert Collins
pair programming worx... merge integration and weave
1073
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
1074
class NotLefthandHistory(BzrError):
1075
1076
    _fmt = "Supplied history does not follow left-hand parents"
1077
1078
    internal_error = True
1079
1080
    def __init__(self, history):
1081
        BzrError.__init__(self, history=history)
1082
1083
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1084
class UnrelatedBranches(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1085
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1086
    _fmt = ("Branches have no common ancestor, and"
1087
            " no merge base revision was specified.")
2067.3.2 by Martin Pool
Error cleanup review comments:
1088
1089
    internal_error = False
1740.5.6 by Martin Pool
Clean up many exception classes.
1090
1091
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1092
class NoCommonAncestor(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1093
    
2067.3.2 by Martin Pool
Error cleanup review comments:
1094
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1740.5.6 by Martin Pool
Clean up many exception classes.
1095
974.1.80 by Aaron Bentley
Improved merge error handling and testing
1096
    def __init__(self, revision_a, revision_b):
1740.5.6 by Martin Pool
Clean up many exception classes.
1097
        self.revision_a = revision_a
1098
        self.revision_b = revision_b
974.1.80 by Aaron Bentley
Improved merge error handling and testing
1099
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1100
974.1.80 by Aaron Bentley
Improved merge error handling and testing
1101
class NoCommonRoot(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1102
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1103
    _fmt = ("Revisions are not derived from the same root: "
1104
           "%(revision_a)s %(revision_b)s.")
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1105
974.1.80 by Aaron Bentley
Improved merge error handling and testing
1106
    def __init__(self, revision_a, revision_b):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1107
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1108
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1109
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
1110
class NotAncestor(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1111
1112
    _fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
1113
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
1114
    def __init__(self, rev_id, not_ancestor_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1115
        BzrError.__init__(self, rev_id=rev_id,
1116
            not_ancestor_id=not_ancestor_id)
1185.1.12 by Robert Collins
merge in lsdiff/filterdiff friendliness
1117
1118
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
1119
class InstallFailed(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1120
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
1121
    def __init__(self, revisions):
2116.3.1 by John Arbash Meinel
Cleanup error tests
1122
        revision_str = ", ".join(str(r) for r in revisions)
1123
        msg = "Could not install revisions:\n%s" % revision_str
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
1124
        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
1125
        self.revisions = revisions
1154 by Martin Pool
- fix imports for moved errors
1126
1127
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
1128
class AmbiguousBase(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1129
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
1130
    def __init__(self, bases):
1131
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1132
                DeprecationWarning)
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1133
        msg = ("The correct base is unclear, because %s are all equally close"
1134
                % ", ".join(bases))
1614.2.13 by Olaf Conradi
Re-added AmbiguousBase with a deprecated warning.
1135
        BzrError.__init__(self, msg)
1136
        self.bases = bases
1137
1138
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1139
class NoCommits(BzrError):
1140
1141
    _fmt = "Branch %(branch)s has no commits."
1948.4.20 by John Arbash Meinel
Make NoCommits a BzrNewError
1142
974.1.80 by Aaron Bentley
Improved merge error handling and testing
1143
    def __init__(self, branch):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1144
        BzrError.__init__(self, branch=branch)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
1145
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1146
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
1147
class UnlistableStore(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1148
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
1149
    def __init__(self, store):
1150
        BzrError.__init__(self, "Store %s is not listable" % store)
1151
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1152
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1153
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
1154
class UnlistableBranch(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1155
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
1156
    def __init__(self, br):
1157
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1392 by Robert Collins
reinstate testfetch test case
1158
1159
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1160
class BoundBranchOutOfDate(BzrError):
1161
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1162
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1163
            " %(master)s.")
2067.3.2 by Martin Pool
Error cleanup review comments:
1164
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
1165
    def __init__(self, branch, master):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1166
        BzrError.__init__(self)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
1167
        self.branch = branch
1168
        self.master = master
1169
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1170
        
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1171
class CommitToDoubleBoundBranch(BzrError):
1172
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1173
    _fmt = ("Cannot commit to branch %(branch)s."
1174
            " It is bound to %(master)s, which is bound to %(remote)s.")
2067.3.2 by Martin Pool
Error cleanup review comments:
1175
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
1176
    def __init__(self, branch, master, remote):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1177
        BzrError.__init__(self)
1505.1.24 by John Arbash Meinel
Updated commit to handle bound branches. Included test to handle commit after merge
1178
        self.branch = branch
1179
        self.master = master
1180
        self.remote = remote
1181
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
1182
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1183
class OverwriteBoundBranch(BzrError):
1184
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1185
    _fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
1186
1505.1.25 by John Arbash Meinel
Updated pull. Now all paths which call set_revision_history maintain the branch invariant. All tests pass.
1187
    def __init__(self, branch):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1188
        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.
1189
        self.branch = branch
1190
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
1191
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1192
class BoundBranchConnectionFailure(BzrError):
1193
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1194
    _fmt = ("Unable to connect to target of bound branch %(branch)s"
1195
            " => %(target)s: %(error)s")
2067.3.2 by Martin Pool
Error cleanup review comments:
1196
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
1197
    def __init__(self, branch, target, error):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1198
        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
1199
        self.branch = branch
1200
        self.target = target
1201
        self.error = error
1202
1203
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1204
class WeaveError(BzrError):
1205
1206
    _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.
1207
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1208
    def __init__(self, message=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1209
        BzrError.__init__(self)
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1210
        self.message = message
1211
1212
1213
class WeaveRevisionAlreadyPresent(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1214
1215
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
1216
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1217
    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.
1218
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1219
        WeaveError.__init__(self)
1220
        self.revision_id = revision_id
1221
        self.weave = weave
1222
1223
1224
class WeaveRevisionNotPresent(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1225
1226
    _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.
1227
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1228
    def __init__(self, revision_id, weave):
1229
        WeaveError.__init__(self)
1230
        self.revision_id = revision_id
1231
        self.weave = weave
1232
1233
1234
class WeaveFormatError(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1235
1236
    _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.
1237
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
1238
    def __init__(self, what):
1239
        WeaveError.__init__(self)
1240
        self.what = what
1241
1242
1243
class WeaveParentMismatch(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1244
1245
    _fmt = "Parents are mismatched between two revisions."
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1246
    
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
1247
1185.50.23 by John Arbash Meinel
Adding sha1 check when weave extracts a text.
1248
class WeaveInvalidChecksum(WeaveError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1249
1250
    _fmt = "Text did not match it's checksum: %(message)s"
1251
1252
1253
class WeaveTextDiffers(WeaveError):
1254
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1255
    _fmt = ("Weaves differ on text content. Revision:"
1256
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1257
1258
    def __init__(self, revision_id, weave_a, weave_b):
1259
        WeaveError.__init__(self)
1260
        self.revision_id = revision_id
1261
        self.weave_a = weave_a
1262
        self.weave_b = weave_b
1263
1264
1265
class WeaveTextDiffers(WeaveError):
1266
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1267
    _fmt = ("Weaves differ on text content. Revision:"
1268
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1269
1270
    def __init__(self, revision_id, weave_a, weave_b):
1271
        WeaveError.__init__(self)
1272
        self.revision_id = revision_id
1273
        self.weave_a = weave_a
1274
        self.weave_b = weave_b
1275
1276
1277
class VersionedFileError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1278
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1279
    _fmt = "Versioned file error"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1280
1281
1282
class RevisionNotPresent(VersionedFileError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1283
    
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1284
    _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.
1285
1286
    def __init__(self, revision_id, file_id):
1287
        VersionedFileError.__init__(self)
1288
        self.revision_id = revision_id
1289
        self.file_id = file_id
1290
1291
1292
class RevisionAlreadyPresent(VersionedFileError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1293
    
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1294
    _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.
1295
1296
    def __init__(self, revision_id, file_id):
1297
        VersionedFileError.__init__(self)
1298
        self.revision_id = revision_id
1299
        self.file_id = file_id
1300
1301
2520.4.71 by Aaron Bentley
Update test to accept VersionedFileInvalidChecksum instead of TestamentMismatch
1302
class VersionedFileInvalidChecksum(VersionedFileError):
1303
1304
    _fmt = "Text did not match its checksum: %(message)s"
1305
1306
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1307
class KnitError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1308
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1309
    _fmt = "Knit error"
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1310
2208.1.1 by John Arbash Meinel
Making KnitError and children internal errors.
1311
    internal_error = True
1312
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1313
2670.3.1 by Andrew Bennetts
Add get_data_stream/insert_data_stream to KnitVersionedFile.
1314
class KnitCorrupt(KnitError):
1315
1316
    _fmt = "Knit %(filename)s corrupt: %(how)s"
1317
1318
    def __init__(self, filename, how):
1319
        KnitError.__init__(self)
1320
        self.filename = filename
1321
        self.how = how
1322
1323
1324
class KnitDataStreamIncompatible(KnitError):
1325
1326
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1327
1328
    def __init__(self, stream_format, target_format):
1329
        self.stream_format = stream_format
1330
        self.target_format = target_format
1331
        
1332
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1333
class KnitHeaderError(KnitError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1334
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1335
    _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.
1336
2171.1.1 by John Arbash Meinel
Knit index files should ignore empty indexes rather than consider them corrupt.
1337
    def __init__(self, badline, filename):
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1338
        KnitError.__init__(self)
1339
        self.badline = badline
2171.1.1 by John Arbash Meinel
Knit index files should ignore empty indexes rather than consider them corrupt.
1340
        self.filename = filename
1563.2.1 by Robert Collins
Merge in a variation of the versionedfile api from versioned-file.
1341
2196.2.5 by John Arbash Meinel
Add an exception class when the knit index storage method is unknown, and properly test for it
1342
class KnitIndexUnknownMethod(KnitError):
1343
    """Raised when we don't understand the storage method.
1344
1345
    Currently only 'fulltext' and 'line-delta' are supported.
1346
    """
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1347
    
2196.2.5 by John Arbash Meinel
Add an exception class when the knit index storage method is unknown, and properly test for it
1348
    _fmt = ("Knit index %(filename)s does not have a known method"
1349
            " in options: %(options)r")
1350
1351
    def __init__(self, filename, options):
1352
        KnitError.__init__(self)
1353
        self.filename = filename
1354
        self.options = options
1355
1356
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1357
class NoSuchExportFormat(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1358
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1359
    _fmt = "Export format %(format)r not supported"
1360
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
1361
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1362
        BzrError.__init__(self)
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
1363
        self.format = format
1364
1365
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1366
class TransportError(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1367
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1368
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1824.2.1 by Johan Rydberg
Let TransportError inherit BzrNerError.
1369
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1370
    def __init__(self, msg=None, orig_error=None):
1371
        if msg is None and orig_error is not None:
1372
            msg = str(orig_error)
1824.2.1 by Johan Rydberg
Let TransportError inherit BzrNerError.
1373
        if orig_error is None:
1374
            orig_error = ''
1375
        if msg is None:
1376
            msg =  ''
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1377
        self.msg = msg
1378
        self.orig_error = orig_error
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1379
        BzrError.__init__(self)
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1380
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1381
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1382
class TooManyConcurrentRequests(BzrError):
1383
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1384
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
1385
            " Be sure to finish_writing and finish_reading on the"
2018.5.134 by Andrew Bennetts
Fix the TooManyConcurrentRequests error message.
1386
            " currently open request.")
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1387
1388
    internal_error = True
1389
1390
    def __init__(self, medium):
1391
        self.medium = medium
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1392
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1393
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.
1394
class SmartProtocolError(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1395
1396
    _fmt = "Generic bzr smart protocol error: %(details)s"
1910.19.13 by Andrew Bennetts
Address various review comments.
1397
1398
    def __init__(self, details):
1399
        self.details = details
1400
1401
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1402
# A set of semi-meaningful errors which can be thrown
1403
class TransportNotPossible(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1404
1405
    _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
1406
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
1407
1408
class ConnectionError(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1409
1410
    _fmt = "Connection error: %(msg)s %(orig_error)s"
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
1411
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1412
2052.4.4 by John Arbash Meinel
Create a SocketConnectionError to make creating nice errors easier
1413
class SocketConnectionError(ConnectionError):
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1414
1415
    _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
1416
1417
    def __init__(self, host, port=None, msg=None, orig_error=None):
1418
        if msg is None:
1419
            msg = 'Failed to connect to'
1420
        if orig_error is None:
1421
            orig_error = ''
1422
        else:
1423
            orig_error = '; ' + str(orig_error)
1424
        ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
1425
        self.host = host
1426
        if port is None:
1427
            self.port = ''
1428
        else:
1429
            self.port = ':%s' % port
1430
1431
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1432
class ConnectionReset(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1433
1434
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
1435
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1436
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1437
class InvalidRange(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1438
1439
    _fmt = "Invalid range access in %(path)s at %(offset)s."
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1440
    
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1441
    def __init__(self, path, offset):
1442
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1443
                                       % (path, offset)))
1979.1.1 by John Arbash Meinel
Fix bug #57723, parse boundary="" correctly, since Squid uses it
1444
        self.path = path
1445
        self.offset = offset
1786.1.8 by John Arbash Meinel
[merge] Johan Rydberg test updates
1446
1447
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1448
class InvalidHttpResponse(TransportError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1449
1450
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1451
1786.1.31 by John Arbash Meinel
Update http errors to properly use BzrNewError
1452
    def __init__(self, path, msg, orig_error=None):
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1453
        self.path = path
1786.1.31 by John Arbash Meinel
Update http errors to properly use BzrNewError
1454
        TransportError.__init__(self, msg, orig_error=orig_error)
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1455
1456
1457
class InvalidHttpRange(InvalidHttpResponse):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1458
1459
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1460
    
1786.1.13 by John Arbash Meinel
Found a few bugs in error handling code, updated tests
1461
    def __init__(self, path, range, msg):
1462
        self.range = range
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1463
        InvalidHttpResponse.__init__(self, path, msg)
1464
1465
1466
class InvalidHttpContentType(InvalidHttpResponse):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1467
1468
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1469
    
1786.1.17 by John Arbash Meinel
Adding tests for _parse_boundary.
1470
    def __init__(self, path, ctype, msg):
1471
        self.ctype = ctype
1472
        InvalidHttpResponse.__init__(self, path, msg)
1786.1.13 by John Arbash Meinel
Found a few bugs in error handling code, updated tests
1473
1474
2164.2.1 by v.ladeuil+lp at free
First rough http branch redirection implementation.
1475
class RedirectRequested(TransportError):
1476
1477
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1478
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1479
    def __init__(self, source, target, is_permament=False, qual_proto=None):
2164.2.1 by v.ladeuil+lp at free
First rough http branch redirection implementation.
1480
        self.source = source
1481
        self.target = target
1482
        if is_permament:
1483
            self.permanently = ' permanently'
1484
        else:
1485
            self.permanently = ''
1486
        self.is_permament = is_permament
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1487
        self._qualified_proto = qual_proto
2164.2.7 by v.ladeuil+lp at free
First implementation of transport hints.
1488
        TransportError.__init__(self)
1489
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1490
    def _requalify_url(self, url):
1491
        """Restore the qualified proto in front of the url"""
1492
        # When this exception is raised, source and target are in
2164.2.17 by Vincent Ladeuil
Add comments and fix typos
1493
        # user readable format. But some transports may use a
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1494
        # different proto (http+urllib:// will present http:// to
1495
        # the user. If a qualified proto is specified, the code
2164.2.17 by Vincent Ladeuil
Add comments and fix typos
1496
        # trapping the exception can get the qualified urls to
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1497
        # properly handle the redirection themself (creating a
1498
        # new transport object from the target url for example).
2164.2.17 by Vincent Ladeuil
Add comments and fix typos
1499
        # But checking that the scheme of the original and
1500
        # redirected urls are the same can be tricky. (see the
1501
        # FIXME in BzrDir.open_from_transport for the unique use
1502
        # case so far).
2164.2.13 by v.ladeuil+lp at free
Add tests for redirection. Preserve transport decorations.
1503
        if self._qualified_proto is None:
1504
            return url
1505
1506
        # The TODO related to NotBranchError mention that doing
1507
        # that kind of manipulation on the urls may not be the
1508
        # exception object job. On the other hand, this object is
1509
        # the interface between the code and the user so
1510
        # presenting the urls in different ways is indeed its
1511
        # job...
1512
        import urlparse
1513
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1514
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1515
                                   query, fragment))
1516
1517
    def get_source_url(self):
1518
        return self._requalify_url(self.source)
1519
1520
    def get_target_url(self):
2164.2.22 by Vincent Ladeuil
Take Aaron's review comments into account.
1521
        return self._requalify_url(self.target)
1522
1523
1524
class TooManyRedirections(TransportError):
1525
1526
    _fmt = "Too many redirections"
2164.2.7 by v.ladeuil+lp at free
First implementation of transport hints.
1527
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
1528
class ConflictsInTree(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1529
1530
    _fmt = "Working tree has conflicts."
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1531
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1532
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1533
class ParseConfigError(BzrError):
2067.3.2 by Martin Pool
Error cleanup review comments:
1534
1185.12.49 by Aaron Bentley
Switched to ConfigObj
1535
    def __init__(self, errors, filename):
1536
        if filename is None:
1537
            filename = ""
1538
        message = "Error(s) parsing config file %s:\n%s" % \
1539
            (filename, ('\n'.join(e.message for e in errors)))
1540
        BzrError.__init__(self, message)
1185.12.52 by Aaron Bentley
Merged more config stuff from Robert
1541
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1542
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1543
class NoEmailInUsername(BzrError):
1544
1545
    _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
1546
1547
    def __init__(self, username):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1548
        BzrError.__init__(self)
2055.2.2 by John Arbash Meinel
Switch extract_email_address() to use a more specific exception
1549
        self.username = username
1550
1551
1442.1.58 by Robert Collins
gpg signing of content
1552
class SigningFailed(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1553
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1554
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1555
1442.1.58 by Robert Collins
gpg signing of content
1556
    def __init__(self, command_line):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1557
        BzrError.__init__(self, command_line=command_line)
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1558
1551.2.1 by Aaron Bentley
recommit 1527 PEP8 fixes
1559
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1560
class WorkingTreeNotRevision(BzrError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1561
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1562
    _fmt = ("The working tree for %(basedir)s has changed since" 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1563
            " the last commit, but weave merge requires that it be"
1564
            " unchanged")
1565
1185.12.83 by Aaron Bentley
Preliminary weave merge support
1566
    def __init__(self, tree):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1567
        BzrError.__init__(self, basedir=tree.basedir)
1568
1569
1570
class CantReprocessAndShowBase(BzrError):
1571
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1572
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
1573
           "the relationship of conflicting lines to the base")
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1574
1575
1576
class GraphCycleError(BzrError):
1577
1578
    _fmt = "Cycle in graph %(graph)r"
2067.3.2 by Martin Pool
Error cleanup review comments:
1579
1185.16.114 by mbp at sourcefrog
Improved topological sort
1580
    def __init__(self, graph):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1581
        BzrError.__init__(self)
1185.16.114 by mbp at sourcefrog
Improved topological sort
1582
        self.graph = graph
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1583
1505.1.23 by John Arbash Meinel
Whitespace cleanup of bzrlib.errors
1584
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1585
class WritingCompleted(BzrError):
1586
1587
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1588
            "called upon it - accept bytes may not be called anymore.")
1589
1590
    internal_error = True
1591
1592
    def __init__(self, request):
1593
        self.request = request
1594
1595
1596
class WritingNotComplete(BzrError):
1597
1598
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1599
            "called upon it - until the write phase is complete no "
1600
            "data may be read.")
1601
1602
    internal_error = True
1603
1604
    def __init__(self, request):
1605
        self.request = request
1606
1607
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1608
class NotConflicted(BzrError):
1609
1610
    _fmt = "File %(filename)s is not conflicted."
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1611
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1612
    def __init__(self, filename):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1613
        BzrError.__init__(self)
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
1614
        self.filename = filename
1185.35.13 by Aaron Bentley
Merged Martin
1615
1505.1.23 by John Arbash Meinel
Whitespace cleanup of bzrlib.errors
1616
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1617
class MediumNotConnected(BzrError):
1618
1619
    _fmt = """The medium '%(medium)s' is not connected."""
1620
1621
    internal_error = True
2018.2.3 by Andrew Bennetts
Starting factoring out the smart server client "medium" from the protocol.
1622
1623
    def __init__(self, medium):
1624
        self.medium = medium
1625
1626
1492 by Robert Collins
Support decoration of commands.
1627
class MustUseDecorated(Exception):
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1628
1629
    _fmt = "A decorating function has requested its original command be used."
1630
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1631
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1632
class NoBundleFound(BzrError):
1633
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
1634
    _fmt = 'No bundle was found in "%(filename)s".'
2067.3.2 by Martin Pool
Error cleanup review comments:
1635
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1636
    def __init__(self, filename):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1637
        BzrError.__init__(self)
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1638
        self.filename = filename
1639
1640
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1641
class BundleNotSupported(BzrError):
1642
1643
    _fmt = "Unable to handle bundle version %(version)s: %(msg)s"
2067.3.2 by Martin Pool
Error cleanup review comments:
1644
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1645
    def __init__(self, version, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1646
        BzrError.__init__(self)
1185.82.3 by John Arbash Meinel
Working on creating a factor for serializing changesets.
1647
        self.version = version
1648
        self.msg = msg
1649
1650
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1651
class MissingText(BzrError):
1652
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1653
    _fmt = ("Branch %(base)s is missing revision"
1654
            " %(text_revision)s of %(file_id)s")
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1655
1185.35.42 by Aaron Bentley
Fixed fetch to be safer wrt ghosts and corrupt branches
1656
    def __init__(self, branch, text_revision, file_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1657
        BzrError.__init__(self)
1185.35.42 by Aaron Bentley
Fixed fetch to be safer wrt ghosts and corrupt branches
1658
        self.branch = branch
1659
        self.base = branch.base
1660
        self.text_revision = text_revision
1661
        self.file_id = file_id
1534.7.5 by Aaron Bentley
Got unique_add under test
1662
2743.1.3 by Robert Collins
Fix vertical whitespace in errors.py. (Robert Collins)
1663
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
1664
class DuplicateFileId(BzrError):
1665
1666
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1667
1668
    def __init__(self, file_id, entry):
1669
        BzrError.__init__(self)
1670
        self.file_id = file_id
1671
        self.entry = entry
1672
1673
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1674
class DuplicateKey(BzrError):
1675
1676
    _fmt = "Key %(key)s is already present in map"
1677
1678
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
1679
class DuplicateHelpPrefix(BzrError):
1680
1681
    _fmt = "The prefix %(prefix)s is in the help search path twice."
1682
1683
    def __init__(self, prefix):
1684
        self.prefix = prefix
1685
1686
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1687
class MalformedTransform(BzrError):
1688
1689
    _fmt = "Tree transform is malformed %(conflicts)r"
1690
1691
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1692
class NoFinalPath(BzrError):
1693
1694
    _fmt = ("No final name for trans_id %(trans_id)r\n"
1695
            "file-id: %(file_id)r\n"
1696
            "root trans-id: %(root_trans_id)r\n")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
1697
1698
    def __init__(self, trans_id, transform):
1699
        self.trans_id = trans_id
1700
        self.file_id = transform.final_file_id(trans_id)
1701
        self.root_trans_id = transform.root
1702
1703
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1704
class BzrBadParameter(BzrError):
1705
1706
    _fmt = "Bad parameter: %(param)r"
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
1707
2540.1.1 by Adeodato Simó
BzrBadParameter is an internal error.
1708
    internal_error = True
1709
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1710
    # This exception should never be thrown, but it is a base class for all
1711
    # parameter-to-function errors.
1712
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1713
    def __init__(self, param):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1714
        BzrError.__init__(self)
1534.3.1 by Robert Collins
* bzrlib.osutils.safe_unicode now exists to provide parameter coercion
1715
        self.param = param
1534.7.32 by Aaron Bentley
Got conflict handling working when conflicts involve existing files
1716
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1717
1185.65.29 by Robert Collins
Implement final review suggestions.
1718
class BzrBadParameterNotUnicode(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1719
1720
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1721
1722
1723
class ReusingTransform(BzrError):
1724
1725
    _fmt = "Attempt to reuse a transform that has already been applied."
1726
1727
1728
class CantMoveRoot(BzrError):
1729
1730
    _fmt = "Moving the root directory is not supported at this time"
1185.65.29 by Robert Collins
Implement final review suggestions.
1731
1534.7.120 by Aaron Bentley
PEP8 fixes
1732
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1733
class BzrMoveFailedError(BzrError):
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1734
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1735
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1736
2220.1.3 by Marius Kruger
* errors.py
1737
    def __init__(self, from_path='', to_path='', extra=None):
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1738
        BzrError.__init__(self)
1739
        if extra:
1740
            self.extra = ': ' + str(extra)
1741
        else:
1742
            self.extra = ''
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1743
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1744
        has_from = len(from_path) > 0
1745
        has_to = len(to_path) > 0
1746
        if has_from:
1747
            self.from_path = osutils.splitpath(from_path)[-1]
1748
        else:
1749
            self.from_path = ''
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1750
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1751
        if has_to:
1752
            self.to_path = osutils.splitpath(to_path)[-1]
1753
        else:
1754
            self.to_path = ''
1755
1756
        self.operator = ""
1757
        if has_from and has_to:
1758
            self.operator = " =>"
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1759
        elif has_from:
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1760
            self.from_path = "from " + from_path
1761
        elif has_to:
1762
            self.operator = "to"
1763
        else:
1764
            self.operator = "file"
1765
1766
1767
class BzrRenameFailedError(BzrMoveFailedError):
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
1768
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1769
    _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
1770
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
1771
    def __init__(self, from_path, to_path, extra=None):
1772
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1773
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1774
class BzrRemoveChangedFilesError(BzrError):
1775
    """Used when user is trying to remove changed files."""
1776
2655.2.5 by Marius Kruger
* Improve BzrRemoveChangedFilesError message.
1777
    _fmt = ("Can't safely remove modified or unknown files:\n"
1778
        "%(changes_as_text)s"
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1779
        "Use --keep to not delete them, or --force to delete them regardless.")
1780
1781
    def __init__(self, tree_delta):
1782
        BzrError.__init__(self)
1783
        self.changes_as_text = tree_delta.get_changes_as_text()
1784
        #self.paths_as_string = '\n'.join(changed_files)
1785
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
2292.1.30 by Marius Kruger
* Minor text fixes.
1786
1787
1185.65.29 by Robert Collins
Implement final review suggestions.
1788
class BzrBadParameterNotString(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1789
1790
    _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.
1791
1792
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1793
class BzrBadParameterMissing(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1794
1795
    _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.
1796
1797
1666.1.6 by Robert Collins
Make knit the default format.
1798
class BzrBadParameterUnicode(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1799
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1800
    _fmt = ("Parameter %(param)s is unicode but"
1801
            " only byte-strings are permitted.")
1666.1.6 by Robert Collins
Make knit the default format.
1802
1803
1804
class BzrBadParameterContainsNewline(BzrBadParameter):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1805
1806
    _fmt = "Parameter %(param)s contains a newline."
1807
1808
1809
class DependencyNotPresent(BzrError):
1810
1811
    _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.
1812
1813
    def __init__(self, library, error):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1814
        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.
1815
1816
1817
class ParamikoNotPresent(DependencyNotPresent):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1818
1819
    _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.
1820
1821
    def __init__(self, error):
1822
        DependencyNotPresent.__init__(self, 'paramiko', error)
1823
1824
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1825
class PointlessMerge(BzrError):
1826
1827
    _fmt = "Nothing to merge."
1828
1829
1830
class UninitializableFormat(BzrError):
1831
1832
    _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.
1833
1834
    def __init__(self, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1835
        BzrError.__init__(self)
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
1836
        self.format = format
1551.3.4 by Aaron Bentley
Implemented default command options
1837
1534.7.156 by Aaron Bentley
PEP8 fixes
1838
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1839
class BadConversionTarget(BzrError):
1840
1841
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1842
1843
    def __init__(self, problem, format):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1844
        BzrError.__init__(self)
1910.2.12 by Aaron Bentley
Implement knit repo format 2
1845
        self.problem = problem
1846
        self.format = format
1847
1848
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1849
class NoDiff(BzrError):
1850
1851
    _fmt = "Diff is not installed on this machine: %(msg)s"
1711.2.56 by John Arbash Meinel
Raise NoDiff if 'diff' not present.
1852
1853
    def __init__(self, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1854
        BzrError.__init__(self, msg=msg)
1855
1856
1857
class NoDiff3(BzrError):
1858
1859
    _fmt = "Diff3 is not installed on this machine."
1860
1861
2794.1.1 by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit.
1862
class ExistingContent(BzrError):
2794.1.3 by Robert Collins
Review feedback.
1863
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
2794.1.1 by Robert Collins
Allow knits to be instructed not to add a text based on a sha, for commit.
1864
1865
    _fmt = "The content being inserted is already present."
1866
1867
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1868
class ExistingLimbo(BzrError):
1869
1870
    _fmt = """This tree contains left-over files from a failed operation.
1871
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1872
    keep, and delete it when you are done."""
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
1873
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1874
    def __init__(self, limbo_dir):
1875
       BzrError.__init__(self)
1876
       self.limbo_dir = limbo_dir
1877
1878
2733.2.11 by Aaron Bentley
Detect irregularities with the pending-deletion directory
1879
class ExistingPendingDeletion(BzrError):
1880
1881
    _fmt = """This tree contains left-over files from a failed operation.
1882
    Please examine %(pending_deletion)s to see if it contains any files you
1883
    wish to keep, and delete it when you are done."""
1884
1885
    def __init__(self, pending_deletion):
1886
       BzrError.__init__(self, pending_deletion=pending_deletion)
1887
1888
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1889
class ImmortalLimbo(BzrError):
1890
2775.1.1 by James Westby
Fix the format string for ImmortalLimbo.
1891
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1892
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1893
    keep, and delete it when you are done."""
1894
1895
    def __init__(self, limbo_dir):
1896
       BzrError.__init__(self)
1897
       self.limbo_dir = limbo_dir
1898
1899
2733.2.11 by Aaron Bentley
Detect irregularities with the pending-deletion directory
1900
class ImmortalPendingDeletion(BzrError):
1901
1902
    _fmt = """Unable to delete transform temporary directory
1903
    %(pending_deletion)s.  Please examine %(pending_deletions)s to see if it
1904
    contains any files you wish to keep, and delete it when you are done."""
1905
1906
    def __init__(self, pending_deletion):
1907
       BzrError.__init__(self, pending_deletion=pending_deletion)
1908
1909
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1910
class OutOfDateTree(BzrError):
1911
1912
    _fmt = "Working tree is out of date, please run 'bzr update'."
1508.1.25 by Robert Collins
Update per review comments.
1913
1914
    def __init__(self, tree):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1915
        BzrError.__init__(self)
1508.1.25 by Robert Collins
Update per review comments.
1916
        self.tree = tree
1534.7.196 by Aaron Bentley
Switched to Rio format for merge-modified list
1917
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
1918
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
1919
class PublicBranchOutOfDate(BzrError):
1920
1921
    _fmt = 'Public branch "%(public_location)s" lacks revision '\
1922
        '"%(revstring)s".'
1923
1924
    def __init__(self, public_location, revstring):
1925
        import bzrlib.urlutils as urlutils
1926
        public_location = urlutils.unescape_for_display(public_location,
1927
                                                        'ascii')
1928
        BzrError.__init__(self, public_location=public_location,
1929
                          revstring=revstring)
1930
1931
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1932
class MergeModifiedFormatError(BzrError):
1933
1934
    _fmt = "Error in merge modified format"
1935
1936
1937
class ConflictFormatError(BzrError):
1938
1939
    _fmt = "Format error in conflict listings"
1940
1941
1942
class CorruptRepository(BzrError):
1943
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1944
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1945
            "Please run bzr reconcile on this repository.")
1570.1.13 by Robert Collins
Check for incorrect revision parentage in the weave during revision access.
1946
1947
    def __init__(self, repo):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1948
        BzrError.__init__(self)
1570.1.13 by Robert Collins
Check for incorrect revision parentage in the weave during revision access.
1949
        self.repo_path = repo.bzrdir.root_transport.base
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1950
1951
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1952
class UpgradeRequired(BzrError):
1953
1954
    _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.
1955
1956
    def __init__(self, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1957
        BzrError.__init__(self)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
1958
        self.path = path
1959
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
1960
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1961
class LocalRequiresBoundBranch(BzrError):
1962
1963
    _fmt = "Cannot perform local-only commits on unbound branches."
1964
1965
1966
class MissingProgressBarFinish(BzrError):
1967
1968
    _fmt = "A nested progress bar was not 'finished' correctly."
1969
1970
1971
class InvalidProgressBarType(BzrError):
1972
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1973
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1974
            " is not a supported type Select one of: %(valid_types)s")
1843.3.7 by John Arbash Meinel
new env var 'BZR_PROGRESS_BAR' to select the exact progress type
1975
1976
    def __init__(self, bar_type, valid_types):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
1977
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1978
1979
1980
class UnsupportedOperation(BzrError):
1981
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1982
    _fmt = ("The method %(mname)s is not supported on"
1983
            " objects of type %(tname)s.")
2067.3.2 by Martin Pool
Error cleanup review comments:
1984
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
1985
    def __init__(self, method, method_self):
1986
        self.method = method
1987
        self.mname = method.__name__
1988
        self.tname = type(method_self).__name__
1558.15.1 by Aaron Bentley
Add text_file function
1989
1990
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.
1991
class CannotSetRevisionId(UnsupportedOperation):
1992
    """Raised when a commit is attempting to set a revision id but cant."""
1993
1994
1995
class NonAsciiRevisionId(UnsupportedOperation):
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
1996
    """Raised when a commit is attempting to set a non-ascii revision id
1997
       but cant.
1998
    """
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.
1999
2000
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2001
class BinaryFile(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2002
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2003
    _fmt = "File is binary but should be text."
2004
2005
2006
class IllegalPath(BzrError):
2007
2008
    _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)
2009
2010
    def __init__(self, path):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2011
        BzrError.__init__(self)
1551.2.55 by abentley
Fix fileid involed tests on win32 (by skipping them for unescaped weave formats)
2012
        self.path = path
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
2013
2014
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2015
class TestamentMismatch(BzrError):
2016
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
2017
    _fmt = """Testament did not match expected value.
2018
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2019
       {%(measured)s}"""
2020
1185.82.118 by Aaron Bentley
Ensure that StrictTestament handles execute bit differences
2021
    def __init__(self, revision_id, expected, measured):
2022
        self.revision_id = revision_id
2023
        self.expected = expected
2024
        self.measured = measured
1185.82.131 by Aaron Bentley
Move BadBundle error (and subclasses) to errors.py
2025
2026
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2027
class NotABundle(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2028
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2029
    _fmt = "Not a bzr revision-bundle: %(text)r"
1185.82.142 by Aaron Bentley
Update for review comments
2030
1185.82.139 by Aaron Bentley
Raise NotABundle when a non-bundle is supplied
2031
    def __init__(self, text):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2032
        BzrError.__init__(self)
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
2033
        self.text = text
2034
2035
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2036
class BadBundle(BzrError): 
2037
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2038
    _fmt = "Bad bzr revision-bundle: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
2039
2040
    def __init__(self, text):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2041
        BzrError.__init__(self)
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
2042
        self.text = text
2043
2044
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2045
class MalformedHeader(BadBundle): 
2046
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2047
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
2048
2049
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2050
class MalformedPatches(BadBundle): 
2051
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2052
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1907.2.1 by Hermann Kraus
Convert bundle errors from Exception to BzrNewError.
2053
2054
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2055
class MalformedFooter(BadBundle): 
2056
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2057
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
2058
1752.3.14 by Andrew Bennetts
Fix shallow bug (bad conflict resolution?) in errors.UnsupportedEOLMarker
2059
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
2060
class UnsupportedEOLMarker(BadBundle):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2061
    
2062
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1907.2.2 by Hermann Kraus
Detect wrong eol markers.
2063
2064
    def __init__(self):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2065
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2066
        # but for this there is not
2067
        BzrError.__init__(self)
2068
2069
2070
class IncompatibleBundleFormat(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2071
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2072
    _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
2073
2074
    def __init__(self, bundle_format, other):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2075
        BzrError.__init__(self)
1910.2.49 by Aaron Bentley
Ensure that 0.8 bundles aren't used with KnitRepository2
2076
        self.bundle_format = bundle_format
2077
        self.other = other
2078
2079
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2080
class BadInventoryFormat(BzrError):
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2081
    
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2082
    _fmt = "Root class for inventory serialization errors"
1910.2.31 by Aaron Bentley
Fix bugs in basis inventory handling, change filename
2083
2084
2085
class UnexpectedInventoryFormat(BadInventoryFormat):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2086
2087
    _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
2088
2089
    def __init__(self, msg):
2090
        BadInventoryFormat.__init__(self, msg=msg)
1910.2.47 by Aaron Bentley
Merge bzr.dev
2091
2092
2100.3.5 by Aaron Bentley
Merge nested-trees work
2093
class RootNotRich(BzrError):
2094
2095
    _fmt = """This operation requires rich root data storage"""
2096
2097
2067.3.3 by Martin Pool
merge bzr.dev and reconcile several changes, also some test fixes
2098
class NoSmartMedium(BzrError):
2099
2100
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2100.3.30 by Aaron Bentley
Merge from bzr.dev
2101
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
2102
    internal_error = True
2018.2.3 by Andrew Bennetts
Starting factoring out the smart server client "medium" from the protocol.
2103
2104
    def __init__(self, transport):
2105
        self.transport = transport
2106
2107
1910.19.2 by Andrew Bennetts
Add a new method ``Transport.get_smart_client()``. This is provided to allow
2108
class NoSmartServer(NotBranchError):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2109
2110
    _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
2111
2112
    def __init__(self, url):
2113
        self.url = url
1752.3.9 by Andrew Bennetts
Merge from bzr.dev
2114
1752.5.3 by Andrew Bennetts
Merge from sftp refactoring 2.
2115
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2116
class UnknownSSH(BzrError):
2117
2118
    _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.
2119
2120
    def __init__(self, vendor):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2121
        BzrError.__init__(self)
1951.1.8 by Andrew Bennetts
Make _get_ssh_vendor return the vendor object, rather than just a string.
2122
        self.vendor = vendor
2123
1908.5.16 by Robert Collins
Merge bzr.dev to resolve conflicts for merging.
2124
2221.5.1 by Dmitry Vasiliev
Added support for Putty's SSH implementation
2125
class SSHVendorNotFound(BzrError):
2126
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
2127
    _fmt = ("Don't know how to handle SSH connections."
2128
            " Please set BZR_SSH environment variable.")
2221.5.1 by Dmitry Vasiliev
Added support for Putty's SSH implementation
2129
2130
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2131
class GhostRevisionUnusableHere(BzrError):
2132
2133
    _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.
2134
2135
    def __init__(self, revision_id):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2136
        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.
2137
        self.revision_id = revision_id
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
2138
2139
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2140
class IllegalUseOfScopeReplacer(BzrError):
2141
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
2142
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2143
            " %(msg)s%(extra)s")
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
2144
2067.3.2 by Martin Pool
Error cleanup review comments:
2145
    internal_error = True
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
2146
2147
    def __init__(self, name, msg, extra=None):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2148
        BzrError.__init__(self)
1996.1.16 by John Arbash Meinel
Raise an exception when ScopeReplacer has been misused
2149
        self.name = name
2150
        self.msg = msg
2151
        if extra:
2152
            self.extra = ': ' + str(extra)
2153
        else:
2154
            self.extra = ''
2155
1996.1.18 by John Arbash Meinel
Add more structured error handling
2156
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2157
class InvalidImportLine(BzrError):
2158
2159
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
1996.1.18 by John Arbash Meinel
Add more structured error handling
2160
2067.3.2 by Martin Pool
Error cleanup review comments:
2161
    internal_error = True
1996.1.18 by John Arbash Meinel
Add more structured error handling
2162
2163
    def __init__(self, text, msg):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2164
        BzrError.__init__(self)
1996.1.18 by John Arbash Meinel
Add more structured error handling
2165
        self.text = text
2166
        self.msg = msg
2167
2168
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2169
class ImportNameCollision(BzrError):
2170
2221.5.9 by Dmitry Vasiliev
Removed trailing whitespaces and wrapped all long lines
2171
    _fmt = ("Tried to import an object to the same name as"
2172
            " an existing object. %(name)s")
1996.1.18 by John Arbash Meinel
Add more structured error handling
2173
2067.3.2 by Martin Pool
Error cleanup review comments:
2174
    internal_error = True
1996.1.18 by John Arbash Meinel
Add more structured error handling
2175
2176
    def __init__(self, name):
2067.3.1 by Martin Pool
Clean up BzrNewError, other exception classes and users.
2177
        BzrError.__init__(self)
1996.1.18 by John Arbash Meinel
Add more structured error handling
2178
        self.name = name
1731.2.2 by Aaron Bentley
Test subsume failure modes
2179
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
2180
1551.12.49 by Aaron Bentley
Proper error when deserializing junk
2181
class NotAMergeDirective(BzrError):
2182
    """File starting with %(firstline)r is not a merge directive"""
2183
    def __init__(self, firstline):
2184
        BzrError.__init__(self, firstline=firstline)
2185
2186
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
2187
class NoMergeSource(BzrError):
2188
    """Raise if no merge source was specified for a merge directive"""
2189
2190
    _fmt = "A merge directive must provide either a bundle or a public"\
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
2191
        " branch location."
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
2192
2193
2520.4.73 by Aaron Bentley
Implement new merge directive format
2194
class IllegalMergeDirectivePayload(BzrError):
2195
    """A merge directive contained something other than a patch or bundle"""
2196
2197
    _fmt = "Bad merge directive payload %(start)r"
2198
2199
    def __init__(self, start):
2200
        BzrError(self)
2201
        self.start = start
2202
2203
2520.4.105 by Aaron Bentley
Implement patch verification
2204
class PatchVerificationFailed(BzrError):
2205
    """A patch from a merge directive could not be verified"""
2206
2520.4.106 by Aaron Bentley
Clarify what patch verification failure means
2207
    _fmt = "Preview patch does not match requested changes."
2520.4.105 by Aaron Bentley
Implement patch verification
2208
2209
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
2210
class PatchMissing(BzrError):
2211
    """Raise a patch type was specified but no patch supplied"""
2212
2213
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
2214
2215
    def __init__(self, patch_type):
2216
        BzrError.__init__(self)
2217
        self.patch_type = patch_type
1551.12.25 by Aaron Bentley
Merge bzr.dev
2218
2219
2100.3.9 by Aaron Bentley
Clean up BzrNewError usage
2220
class UnsupportedInventoryKind(BzrError):
2221
    
2222
    _fmt = """Unsupported entry kind %(kind)s"""
2100.3.1 by Aaron Bentley
Start roundtripping tree-reference entries
2223
2224
    def __init__(self, kind):
2225
        self.kind = kind
2100.3.5 by Aaron Bentley
Merge nested-trees work
2226
2227
2100.3.9 by Aaron Bentley
Clean up BzrNewError usage
2228
class BadSubsumeSource(BzrError):
2229
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
2230
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
1731.2.5 by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root
2231
1731.2.2 by Aaron Bentley
Test subsume failure modes
2232
    def __init__(self, tree, other_tree, reason):
2233
        self.tree = tree
2234
        self.other_tree = other_tree
2235
        self.reason = reason
1731.2.5 by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root
2236
2237
2100.3.9 by Aaron Bentley
Clean up BzrNewError usage
2238
class SubsumeTargetNeedsUpgrade(BzrError):
2239
    
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
2240
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
1731.2.5 by Aaron Bentley
Ensure versionedfile will be produced for subsumed tree root
2241
2242
    def __init__(self, other_tree):
2243
        self.other_tree = other_tree
2100.3.8 by Aaron Bentley
Add add_reference
2244
2245
2246
class BadReferenceTarget(BzrError):
2247
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
2248
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2745.3.1 by Daniel Watkins
Modified errors.py to quote paths just before full stops. Also added some full stops to error messages without them.
2249
           "%(reason)s"
2100.3.8 by Aaron Bentley
Add add_reference
2250
2251
    internal_error = True
2252
2253
    def __init__(self, tree, other_tree, reason):
2254
        self.tree = tree
2255
        self.other_tree = other_tree
2256
        self.reason = reason
2255.2.182 by Martin Pool
merge dirstate and trunk
2257
2258
2220.2.2 by Martin Pool
Add tag command and basic implementation
2259
class NoSuchTag(BzrError):
2260
2261
    _fmt = "No such tag: %(tag_name)s"
2262
2263
    def __init__(self, tag_name):
2264
        self.tag_name = tag_name
2220.2.4 by Martin Pool
Repositories which don't support tags now give a better message
2265
2266
2267
class TagsNotSupported(BzrError):
2268
2221.5.14 by Dmitry Vasiliev
Wrapped long lines
2269
    _fmt = ("Tags not supported by %(branch)s;"
2382.3.1 by Ian Clatworthy
Better tag/tags error message (#97674)
2270
            " you may be able to use bzr upgrade --dirstate-tags.")
2220.2.5 by Martin Pool
Better TagsNotSupported message
2271
2220.2.21 by Martin Pool
Add tag --delete command and implementation
2272
    def __init__(self, branch):
2220.2.23 by Martin Pool
Fix TagsNotSupportedError
2273
        self.branch = branch
2220.2.42 by Martin Pool
Tag command refuses to replace existing tags unless you force it.
2274
2221.5.21 by Dmitry Vasiliev
Reverted trailing whitespace removal
2275
        
2220.2.42 by Martin Pool
Tag command refuses to replace existing tags unless you force it.
2276
class TagAlreadyExists(BzrError):
2277
2278
    _fmt = "Tag %(tag_name)s already exists."
2279
2280
    def __init__(self, tag_name):
2281
        self.tag_name = tag_name
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
2282
2283
2376.4.7 by jml at canonical
- Add docstrings to tests.
2284
class MalformedBugIdentifier(BzrError):
2285
2376.4.13 by Jonathan Lange
Some stylistic cleanups
2286
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2376.4.7 by jml at canonical
- Add docstrings to tests.
2287
2288
    def __init__(self, bug_id, reason):
2289
        self.bug_id = bug_id
2290
        self.reason = reason
2376.4.26 by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation.
2291
2292
2293
class UnknownBugTrackerAbbreviation(BzrError):
2294
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
2295
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2376.4.27 by Jonathan Lange
Include branch information in UnknownBugTrackerAbbreviation
2296
            "on %(branch)s")
2376.4.26 by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation.
2297
2376.4.27 by Jonathan Lange
Include branch information in UnknownBugTrackerAbbreviation
2298
    def __init__(self, abbreviation, branch):
2376.4.26 by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation.
2299
        self.abbreviation = abbreviation
2376.4.27 by Jonathan Lange
Include branch information in UnknownBugTrackerAbbreviation
2300
        self.branch = branch
2376.4.38 by Jonathan Lange
Merge bzr.dev, resolving conflicts in error code.
2301
2302
2018.5.163 by Andrew Bennetts
Deal with various review comments from Robert.
2303
class UnexpectedSmartServerResponse(BzrError):
2304
2305
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2306
2307
    def __init__(self, response_tuple):
2308
        self.response_tuple = response_tuple
2506.2.1 by Andrew Bennetts
Start implementing container format reading and writing.
2309
2310
2311
class ContainerError(BzrError):
2312
    """Base class of container errors."""
2313
2314
2315
class UnknownContainerFormatError(ContainerError):
2316
2317
    _fmt = "Unrecognised container format: %(container_format)r"
2318
    
2319
    def __init__(self, container_format):
2320
        self.container_format = container_format
2321
2322
2323
class UnexpectedEndOfContainerError(ContainerError):
2324
2325
    _fmt = "Unexpected end of container stream"
2326
2327
    internal_error = False
2328
2329
2330
class UnknownRecordTypeError(ContainerError):
2331
2332
    _fmt = "Unknown record type: %(record_type)r"
2333
2334
    def __init__(self, record_type):
2335
        self.record_type = record_type
2336
2337
2506.3.1 by Andrew Bennetts
More progress:
2338
class InvalidRecordError(ContainerError):
2339
2340
    _fmt = "Invalid record: %(reason)s"
2341
2342
    def __init__(self, reason):
2343
        self.reason = reason
2344
2506.2.6 by Andrew Bennetts
Add validate method to ContainerReader and BytesRecordReader.
2345
2346
class ContainerHasExcessDataError(ContainerError):
2347
2348
    _fmt = "Container has data after end marker: %(excess)r"
2349
2350
    def __init__(self, excess):
2351
        self.excess = excess
2352
2506.6.1 by Andrew Bennetts
Return a callable instead of a str from read, and add more validation.
2353
2354
class DuplicateRecordNameError(ContainerError):
2355
2745.3.3 by Daniel Watkins
Changed to remove need for escaping of quotes.
2356
    _fmt = "Container has multiple records with the same name: %(name)s"
2506.6.1 by Andrew Bennetts
Return a callable instead of a str from read, and add more validation.
2357
2358
    def __init__(self, name):
2359
        self.name = name
2360
2520.4.107 by Aaron Bentley
Merge bzr.dev
2361
2535.2.1 by Adeodato Simó
New SMTPConnection class, a reduced version of that in bzr-email.
2362
class NoDestinationAddress(BzrError):
2363
2364
    _fmt = "Message does not have a destination address."
2535.2.2 by Adeodato Simó
Swap the order of internal_error and _fmt for consistency.
2365
2366
    internal_error = True
2535.2.4 by Adeodato Simó
Don't use BzrCommandError in non-UI code; create and use an SMTPError
2367
2368
2369
class SMTPError(BzrError):
2370
2371
    _fmt = "SMTP error: %(error)s"
2372
2373
    def __init__(self, error):
2374
        self.error = error
2681.1.9 by Aaron Bentley
Add support for mail-from-editor
2375
2376
2377
class NoMessageSupplied(BzrError):
2378
2379
    _fmt = "No message supplied."
2681.1.10 by Aaron Bentley
Clean up handling of unknown mail clients
2380
2381
2382
class UnknownMailClient(BzrError):
2383
2384
    _fmt = "Unknown mail client: %(mail_client)s"
2385
2386
    def __init__(self, mail_client):
2387
        BzrError.__init__(self, mail_client=mail_client)
2681.1.18 by Aaron Bentley
Refactor to increase code sharing, allow multiple command names for tbird
2388
2389
2390
class MailClientNotFound(BzrError):
2391
2392
    _fmt = "Unable to find mail client with the following names:"\
2393
        " %(mail_command_list_string)s"
2394
2395
    def __init__(self, mail_command_list):
2396
        mail_command_list_string = ', '.join(mail_command_list)
2397
        BzrError.__init__(self, mail_command_list=mail_command_list,
2398
                          mail_command_list_string=mail_command_list_string)
2681.1.31 by Aaron Bentley
Merge bzr.dev
2399
2694.2.1 by Aaron Bentley
Make error handling nicer when SMTP server not working
2400
class SMTPConnectionRefused(SMTPError):
2401
2402
    _fmt = "SMTP connection to %(host)s refused"
2403
2404
    def __init__(self, error, host):
2405
        self.error = error
2406
        self.host = host
2407
2408
2409
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2410
2411
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
2412
2413
2414
class BzrDirError(BzrError):
2415
2416
    def __init__(self, bzrdir):
2417
        import bzrlib.urlutils as urlutils
2418
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2419
                                                    'ascii')
2420
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2421
2422
2423
class AlreadyBranch(BzrDirError):
2424
2425
    _fmt = "'%(display_url)s' is already a branch."
2426
2427
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
2428
class AlreadyTree(BzrDirError):
2429
2430
    _fmt = "'%(display_url)s' is already a tree."
2431
2432
2433
class AlreadyCheckout(BzrDirError):
2434
2435
    _fmt = "'%(display_url)s' is already a checkout."
2436
2437
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
2438
class ReconfigurationNotSupported(BzrDirError):
2439
2440
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2441
2442
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
2443
class NoBindLocation(BzrDirError):
2444
2445
    _fmt = "No location could be found to bind to at %(display_url)s."
2446
2447
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
2448
class UncommittedChanges(BzrError):
2449
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
2450
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
2451
2452
    def __init__(self, tree):
2453
        import bzrlib.urlutils as urlutils
2454
        display_url = urlutils.unescape_for_display(
2455
            tree.bzrdir.root_transport.base, 'ascii')
2456
        BzrError.__init__(self, tree=tree, display_url=display_url)