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