/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2007-09-24 06:42:21 UTC
  • mfrom: (2713.2.3 error-exitcode)
  • mto: This revision was merged to the branch mainline in revision 2874.
  • Revision ID: mbp@sourcefrog.net-20070924064221-nu12try0hbilenlj
Return exitcode 4 on internal error

Show diffs side-by-side

added added

removed removed

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