/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: 2009-12-14 06:06:59 UTC
  • mfrom: (4889 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4891.
  • Revision ID: mbp@sourcefrog.net-20091214060659-1ucv8hpnky0cbnaj
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
 
21
20
from bzrlib import (
22
21
    osutils,
23
22
    symbol_versioning,
32
31
 
33
32
 
34
33
# 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 
 
34
# python exceptions?   A list of values with no names seems less useful
36
35
# to me.
37
36
 
38
 
# TODO: Perhaps convert the exception to a string at the moment it's 
 
37
# TODO: Perhaps convert the exception to a string at the moment it's
39
38
# constructed to make sure it will succeed.  But that says nothing about
40
39
# exceptions that are never raised.
41
40
 
62
61
    :cvar _fmt: Format string to display the error; this is expanded
63
62
    by the instance's dict.
64
63
    """
65
 
    
 
64
 
66
65
    internal_error = False
67
66
 
68
67
    def __init__(self, msg=None, **kwds):
73
72
        arguments can be given.  The first is for generic "user" errors which
74
73
        are not intended to be caught and so do not need a specific subclass.
75
74
        The second case is for use with subclasses that provide a _fmt format
76
 
        string to print the arguments.  
 
75
        string to print the arguments.
77
76
 
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 
 
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
81
80
        parameters.
82
81
 
83
82
        :param msg: If given, this is the literal complete text for the error,
84
 
        not subject to expansion.
 
83
           not subject to expansion. 'msg' is used instead of 'message' because
 
84
           python evolved and, in 2.6, forbids the use of 'message'.
85
85
        """
86
86
        StandardError.__init__(self)
87
87
        if msg is not None:
93
93
            for key, value in kwds.items():
94
94
                setattr(self, key, value)
95
95
 
96
 
    def __str__(self):
 
96
    def _format(self):
97
97
        s = getattr(self, '_preformatted_string', None)
98
98
        if s is not None:
99
 
            # contains a preformatted message; must be cast to plain str
100
 
            return str(s)
 
99
            # contains a preformatted message
 
100
            return s
101
101
        try:
102
102
            fmt = self._get_format_string()
103
103
            if fmt:
104
104
                d = dict(self.__dict__)
105
 
                # special case: python2.5 puts the 'message' attribute in a
106
 
                # slot, so it isn't seen in __dict__
107
 
                d['message'] = getattr(self, 'message', 'no message')
108
105
                s = fmt % d
109
106
                # __str__() should always return a 'str' object
110
107
                # never a 'unicode' object.
111
 
                if isinstance(s, unicode):
112
 
                    return s.encode('utf8')
113
108
                return s
114
109
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
115
110
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
118
113
                   getattr(self, '_fmt', None),
119
114
                   e)
120
115
 
 
116
    def __unicode__(self):
 
117
        u = self._format()
 
118
        if isinstance(u, str):
 
119
            # Try decoding the str using the default encoding.
 
120
            u = unicode(u)
 
121
        elif not isinstance(u, unicode):
 
122
            # Try to make a unicode object from it, because __unicode__ must
 
123
            # return a unicode object.
 
124
            u = unicode(u)
 
125
        return u
 
126
 
 
127
    def __str__(self):
 
128
        s = self._format()
 
129
        if isinstance(s, unicode):
 
130
            s = s.encode('utf8')
 
131
        else:
 
132
            # __str__ must return a str.
 
133
            s = str(s)
 
134
        return s
 
135
 
 
136
    def __repr__(self):
 
137
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
138
 
121
139
    def _get_format_string(self):
122
140
        """Return format string for this exception or None"""
123
141
        fmt = getattr(self, '_fmt', None)
135
153
               getattr(self, '_fmt', None),
136
154
               )
137
155
 
 
156
    def __eq__(self, other):
 
157
        if self.__class__ is not other.__class__:
 
158
            return NotImplemented
 
159
        return self.__dict__ == other.__dict__
 
160
 
138
161
 
139
162
class InternalBzrError(BzrError):
140
163
    """Base class for errors that are internal in nature.
181
204
 
182
205
 
183
206
class AlreadyBuilding(BzrError):
184
 
    
 
207
 
185
208
    _fmt = "The tree builder is already building a tree."
186
209
 
187
210
 
193
216
 
194
217
 
195
218
class BzrCheckError(InternalBzrError):
196
 
    
197
 
    _fmt = "Internal check failed: %(message)s"
198
 
 
199
 
    def __init__(self, message):
200
 
        BzrError.__init__(self)
201
 
        self.message = message
 
219
 
 
220
    _fmt = "Internal check failed: %(msg)s"
 
221
 
 
222
    def __init__(self, msg):
 
223
        BzrError.__init__(self)
 
224
        self.msg = msg
 
225
 
 
226
 
 
227
class DirstateCorrupt(BzrError):
 
228
 
 
229
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
230
 
 
231
    def __init__(self, state, msg):
 
232
        BzrError.__init__(self)
 
233
        self.state = state
 
234
        self.msg = msg
202
235
 
203
236
 
204
237
class DisabledMethod(InternalBzrError):
232
265
 
233
266
 
234
267
class InvalidEntryName(InternalBzrError):
235
 
    
 
268
 
236
269
    _fmt = "Invalid entry name: %(name)s"
237
270
 
238
271
    def __init__(self, name):
241
274
 
242
275
 
243
276
class InvalidRevisionNumber(BzrError):
244
 
    
 
277
 
245
278
    _fmt = "Invalid revision number %(revno)s"
246
279
 
247
280
    def __init__(self, revno):
296
329
class NoSuchId(BzrError):
297
330
 
298
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
299
 
    
 
332
 
300
333
    def __init__(self, tree, file_id):
301
334
        BzrError.__init__(self)
302
335
        self.file_id = file_id
329
362
class NoWorkingTree(BzrError):
330
363
 
331
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
332
 
    
 
365
 
333
366
    def __init__(self, base):
334
367
        BzrError.__init__(self)
335
368
        self.base = base
366
399
    # are not intended to be caught anyway.  UI code need not subclass
367
400
    # BzrCommandError, and non-UI code should not throw a subclass of
368
401
    # BzrCommandError.  ADHB 20051211
369
 
    def __init__(self, msg):
370
 
        # Object.__str__() must return a real string
371
 
        # returning a Unicode string is a python error.
372
 
        if isinstance(msg, unicode):
373
 
            self.msg = msg.encode('utf8')
374
 
        else:
375
 
            self.msg = msg
376
 
 
377
 
    def __str__(self):
378
 
        return self.msg
379
402
 
380
403
 
381
404
class NotWriteLocked(BzrError):
454
477
    def __init__(self, name, value):
455
478
        BzrError.__init__(self, name=name, value=value)
456
479
 
457
 
    
 
480
 
458
481
class StrictCommitFailed(BzrError):
459
482
 
460
483
    _fmt = "Commit refused because there are unknown files in the tree"
463
486
# XXX: Should be unified with TransportError; they seem to represent the
464
487
# same thing
465
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
466
 
# - this is finer than a TransportError - and more useful as such. It 
 
489
# - this is finer than a TransportError - and more useful as such. It
467
490
# differentiates between 'transport has failed' and 'operation on a transport
468
491
# has failed.'
469
492
class PathError(BzrError):
470
 
    
 
493
 
471
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
472
495
 
473
496
    def __init__(self, path, extra=None):
527
550
 
528
551
 
529
552
class ReadingCompleted(InternalBzrError):
530
 
    
 
553
 
531
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
532
555
            "called upon it - the request has been completed and no more "
533
556
            "data may be read.")
562
585
        PathError.__init__(self, base, reason)
563
586
 
564
587
 
 
588
class InvalidRebaseURLs(PathError):
 
589
 
 
590
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
591
 
 
592
    def __init__(self, from_, to):
 
593
        self.from_ = from_
 
594
        self.to = to
 
595
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
596
 
 
597
 
565
598
class UnavailableRepresentation(InternalBzrError):
566
599
 
567
600
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
603
636
        self.url = url
604
637
 
605
638
 
 
639
class UnstackableLocationError(BzrError):
 
640
 
 
641
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
642
 
 
643
    def __init__(self, branch_url, target_url):
 
644
        BzrError.__init__(self)
 
645
        self.branch_url = branch_url
 
646
        self.target_url = target_url
 
647
 
 
648
 
606
649
class UnstackableRepositoryFormat(BzrError):
607
650
 
608
651
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
615
658
 
616
659
 
617
660
class ReadError(PathError):
618
 
    
 
661
 
619
662
    _fmt = """Error reading from %(path)r."""
620
663
 
621
664
 
656
699
 
657
700
# TODO: This is given a URL; we try to unescape it but doing that from inside
658
701
# the exception object is a bit undesirable.
659
 
# TODO: Probably this behavior of should be a common superclass 
 
702
# TODO: Probably this behavior of should be a common superclass
660
703
class NotBranchError(PathError):
661
704
 
662
705
    _fmt = 'Not a branch: "%(path)s".'
731
774
 
732
775
 
733
776
class UnknownFormatError(BzrError):
734
 
    
 
777
 
735
778
    _fmt = "Unknown %(kind)s format: %(format)r"
736
779
 
737
780
    def __init__(self, format, kind='branch'):
740
783
 
741
784
 
742
785
class IncompatibleFormat(BzrError):
743
 
    
 
786
 
744
787
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
745
788
 
746
789
    def __init__(self, format, bzrdir_format):
750
793
 
751
794
 
752
795
class IncompatibleRepositories(BzrError):
753
 
 
754
 
    _fmt = "Repository %(target)s is not compatible with repository"\
755
 
        " %(source)s"
756
 
 
757
 
    def __init__(self, source, target):
758
 
        BzrError.__init__(self, target=target, source=source)
 
796
    """Report an error that two repositories are not compatible.
 
797
 
 
798
    Note that the source and target repositories are permitted to be strings:
 
799
    this exception is thrown from the smart server and may refer to a
 
800
    repository the client hasn't opened.
 
801
    """
 
802
 
 
803
    _fmt = "%(target)s\n" \
 
804
            "is not compatible with\n" \
 
805
            "%(source)s\n" \
 
806
            "%(details)s"
 
807
 
 
808
    def __init__(self, source, target, details=None):
 
809
        if details is None:
 
810
            details = "(no details)"
 
811
        BzrError.__init__(self, target=target, source=source, details=details)
759
812
 
760
813
 
761
814
class IncompatibleRevision(BzrError):
762
 
    
 
815
 
763
816
    _fmt = "Revision is not compatible with %(repo_format)s"
764
817
 
765
818
    def __init__(self, repo_format):
848
901
        BzrError.__init__(self, filename=filename, kind=kind)
849
902
 
850
903
 
 
904
class BadFilenameEncoding(BzrError):
 
905
 
 
906
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
 
907
            ' encoding %(fs_encoding)s')
 
908
 
 
909
    def __init__(self, filename, fs_encoding):
 
910
        BzrError.__init__(self)
 
911
        self.filename = filename
 
912
        self.fs_encoding = fs_encoding
 
913
 
 
914
 
851
915
class ForbiddenControlFileError(BzrError):
852
916
 
853
917
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
955
1019
 
956
1020
class LockContention(LockError):
957
1021
 
958
 
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1022
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
959
1023
    # TODO: show full url for lock, combining the transport and relative
960
1024
    # bits?
961
1025
 
962
1026
    internal_error = False
963
1027
 
964
 
    def __init__(self, lock):
 
1028
    def __init__(self, lock, msg=''):
965
1029
        self.lock = lock
 
1030
        self.msg = msg
966
1031
 
967
1032
 
968
1033
class LockBroken(LockError):
1082
1147
 
1083
1148
class NoSuchRevisionInTree(NoSuchRevision):
1084
1149
    """When using Tree.revision_tree, and the revision is not accessible."""
1085
 
    
 
1150
 
1086
1151
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1087
1152
 
1088
1153
    def __init__(self, tree, revision_id):
1124
1189
class DivergedBranches(BzrError):
1125
1190
 
1126
1191
    _fmt = ("These branches have diverged."
1127
 
            " Use the merge command to reconcile them.")
 
1192
            " Use the missing command to see how.\n"
 
1193
            "Use the merge command to reconcile them.")
1128
1194
 
1129
1195
    def __init__(self, branch1, branch2):
1130
1196
        self.branch1 = branch1
1152
1218
 
1153
1219
 
1154
1220
class NoCommonAncestor(BzrError):
1155
 
    
 
1221
 
1156
1222
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1157
1223
 
1158
1224
    def __init__(self, revision_a, revision_b):
1178
1244
            not_ancestor_id=not_ancestor_id)
1179
1245
 
1180
1246
 
1181
 
class InstallFailed(BzrError):
1182
 
 
1183
 
    def __init__(self, revisions):
1184
 
        revision_str = ", ".join(str(r) for r in revisions)
1185
 
        msg = "Could not install revisions:\n%s" % revision_str
1186
 
        BzrError.__init__(self, msg)
1187
 
        self.revisions = revisions
1188
 
 
1189
 
 
1190
1247
class AmbiguousBase(BzrError):
1191
1248
 
1192
1249
    def __init__(self, bases):
1226
1283
        self.branch = branch
1227
1284
        self.master = master
1228
1285
 
1229
 
        
 
1286
 
1230
1287
class CommitToDoubleBoundBranch(BzrError):
1231
1288
 
1232
1289
    _fmt = ("Cannot commit to branch %(branch)s."
1262
1319
 
1263
1320
class WeaveError(BzrError):
1264
1321
 
1265
 
    _fmt = "Error in processing weave: %(message)s"
 
1322
    _fmt = "Error in processing weave: %(msg)s"
1266
1323
 
1267
 
    def __init__(self, message=None):
 
1324
    def __init__(self, msg=None):
1268
1325
        BzrError.__init__(self)
1269
 
        self.message = message
 
1326
        self.msg = msg
1270
1327
 
1271
1328
 
1272
1329
class WeaveRevisionAlreadyPresent(WeaveError):
1302
1359
class WeaveParentMismatch(WeaveError):
1303
1360
 
1304
1361
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1305
 
    
 
1362
 
1306
1363
 
1307
1364
class WeaveInvalidChecksum(WeaveError):
1308
1365
 
1334
1391
 
1335
1392
 
1336
1393
class VersionedFileError(BzrError):
1337
 
    
 
1394
 
1338
1395
    _fmt = "Versioned file error"
1339
1396
 
1340
1397
 
1341
1398
class RevisionNotPresent(VersionedFileError):
1342
 
    
 
1399
 
1343
1400
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1344
1401
 
1345
1402
    def __init__(self, revision_id, file_id):
1349
1406
 
1350
1407
 
1351
1408
class RevisionAlreadyPresent(VersionedFileError):
1352
 
    
 
1409
 
1353
1410
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1354
1411
 
1355
1412
    def __init__(self, revision_id, file_id):
1364
1421
 
1365
1422
 
1366
1423
class KnitError(InternalBzrError):
1367
 
    
 
1424
 
1368
1425
    _fmt = "Knit error"
1369
1426
 
1370
1427
 
1378
1435
        self.how = how
1379
1436
 
1380
1437
 
 
1438
class SHA1KnitCorrupt(KnitCorrupt):
 
1439
 
 
1440
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1441
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1442
        "sha %(actual)s")
 
1443
 
 
1444
    def __init__(self, filename, actual, expected, key, content):
 
1445
        KnitError.__init__(self)
 
1446
        self.filename = filename
 
1447
        self.actual = actual
 
1448
        self.expected = expected
 
1449
        self.key = key
 
1450
        self.content = content
 
1451
 
 
1452
 
1381
1453
class KnitDataStreamIncompatible(KnitError):
1382
1454
    # Not raised anymore, as we can convert data streams.  In future we may
1383
1455
    # need it again for more exotic cases, so we're keeping it around for now.
1387
1459
    def __init__(self, stream_format, target_format):
1388
1460
        self.stream_format = stream_format
1389
1461
        self.target_format = target_format
1390
 
        
 
1462
 
1391
1463
 
1392
1464
class KnitDataStreamUnknown(KnitError):
1393
1465
    # Indicates a data stream we don't know how to handle.
1396
1468
 
1397
1469
    def __init__(self, stream_format):
1398
1470
        self.stream_format = stream_format
1399
 
        
 
1471
 
1400
1472
 
1401
1473
class KnitHeaderError(KnitError):
1402
1474
 
1412
1484
 
1413
1485
    Currently only 'fulltext' and 'line-delta' are supported.
1414
1486
    """
1415
 
    
 
1487
 
1416
1488
    _fmt = ("Knit index %(filename)s does not have a known method"
1417
1489
            " in options: %(options)r")
1418
1490
 
1422
1494
        self.options = options
1423
1495
 
1424
1496
 
 
1497
class RetryWithNewPacks(BzrError):
 
1498
    """Raised when we realize that the packs on disk have changed.
 
1499
 
 
1500
    This is meant as more of a signaling exception, to trap between where a
 
1501
    local error occurred and the code that can actually handle the error and
 
1502
    code that can retry appropriately.
 
1503
    """
 
1504
 
 
1505
    internal_error = True
 
1506
 
 
1507
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1508
            " %(orig_error)s")
 
1509
 
 
1510
    def __init__(self, context, reload_occurred, exc_info):
 
1511
        """create a new RetryWithNewPacks error.
 
1512
 
 
1513
        :param reload_occurred: Set to True if we know that the packs have
 
1514
            already been reloaded, and we are failing because of an in-memory
 
1515
            cache miss. If set to True then we will ignore if a reload says
 
1516
            nothing has changed, because we assume it has already reloaded. If
 
1517
            False, then a reload with nothing changed will force an error.
 
1518
        :param exc_info: The original exception traceback, so if there is a
 
1519
            problem we can raise the original error (value from sys.exc_info())
 
1520
        """
 
1521
        BzrError.__init__(self)
 
1522
        self.reload_occurred = reload_occurred
 
1523
        self.exc_info = exc_info
 
1524
        self.orig_error = exc_info[1]
 
1525
        # TODO: The global error handler should probably treat this by
 
1526
        #       raising/printing the original exception with a bit about
 
1527
        #       RetryWithNewPacks also not being caught
 
1528
 
 
1529
 
 
1530
class RetryAutopack(RetryWithNewPacks):
 
1531
    """Raised when we are autopacking and we find a missing file.
 
1532
 
 
1533
    Meant as a signaling exception, to tell the autopack code it should try
 
1534
    again.
 
1535
    """
 
1536
 
 
1537
    internal_error = True
 
1538
 
 
1539
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1540
            " context: %(context)s %(orig_error)s")
 
1541
 
 
1542
 
1425
1543
class NoSuchExportFormat(BzrError):
1426
 
    
 
1544
 
1427
1545
    _fmt = "Export format %(format)r not supported"
1428
1546
 
1429
1547
    def __init__(self, format):
1432
1550
 
1433
1551
 
1434
1552
class TransportError(BzrError):
1435
 
    
 
1553
 
1436
1554
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1437
1555
 
1438
1556
    def __init__(self, msg=None, orig_error=None):
1483
1601
 
1484
1602
class SmartMessageHandlerError(InternalBzrError):
1485
1603
 
1486
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
 
1604
    _fmt = ("The message handler raised an exception:\n"
 
1605
            "%(traceback_text)s")
1487
1606
 
1488
1607
    def __init__(self, exc_info):
1489
 
        self.exc_type, self.exc_value, self.tb = exc_info
1490
 
        
 
1608
        import traceback
 
1609
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1610
        self.exc_info = exc_info
 
1611
        traceback_strings = traceback.format_exception(
 
1612
                self.exc_type, self.exc_value, self.exc_tb)
 
1613
        self.traceback_text = ''.join(traceback_strings)
 
1614
 
1491
1615
 
1492
1616
# A set of semi-meaningful errors which can be thrown
1493
1617
class TransportNotPossible(TransportError):
1519
1643
            self.port = ':%s' % port
1520
1644
 
1521
1645
 
 
1646
# XXX: This is also used for unexpected end of file, which is different at the
 
1647
# TCP level from "connection reset".
1522
1648
class ConnectionReset(TransportError):
1523
1649
 
1524
1650
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1565
1691
 
1566
1692
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1567
1693
 
1568
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1694
    def __init__(self, source, target, is_permanent=False):
1569
1695
        self.source = source
1570
1696
        self.target = target
1571
1697
        if is_permanent:
1572
1698
            self.permanently = ' permanently'
1573
1699
        else:
1574
1700
            self.permanently = ''
1575
 
        self._qualified_proto = qual_proto
1576
1701
        TransportError.__init__(self)
1577
1702
 
1578
 
    def _requalify_url(self, url):
1579
 
        """Restore the qualified proto in front of the url"""
1580
 
        # When this exception is raised, source and target are in
1581
 
        # user readable format. But some transports may use a
1582
 
        # different proto (http+urllib:// will present http:// to
1583
 
        # the user. If a qualified proto is specified, the code
1584
 
        # trapping the exception can get the qualified urls to
1585
 
        # properly handle the redirection themself (creating a
1586
 
        # new transport object from the target url for example).
1587
 
        # But checking that the scheme of the original and
1588
 
        # redirected urls are the same can be tricky. (see the
1589
 
        # FIXME in BzrDir.open_from_transport for the unique use
1590
 
        # case so far).
1591
 
        if self._qualified_proto is None:
1592
 
            return url
1593
 
 
1594
 
        # The TODO related to NotBranchError mention that doing
1595
 
        # that kind of manipulation on the urls may not be the
1596
 
        # exception object job. On the other hand, this object is
1597
 
        # the interface between the code and the user so
1598
 
        # presenting the urls in different ways is indeed its
1599
 
        # job...
1600
 
        import urlparse
1601
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1602
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1603
 
                                   query, fragment))
1604
 
 
1605
 
    def get_source_url(self):
1606
 
        return self._requalify_url(self.source)
1607
 
 
1608
 
    def get_target_url(self):
1609
 
        return self._requalify_url(self.target)
1610
 
 
1611
1703
 
1612
1704
class TooManyRedirections(TransportError):
1613
1705
 
1625
1717
        if filename is None:
1626
1718
            filename = ""
1627
1719
        message = "Error(s) parsing config file %s:\n%s" % \
1628
 
            (filename, ('\n'.join(e.message for e in errors)))
 
1720
            (filename, ('\n'.join(e.msg for e in errors)))
1629
1721
        BzrError.__init__(self, message)
1630
1722
 
1631
1723
 
1648
1740
 
1649
1741
class WorkingTreeNotRevision(BzrError):
1650
1742
 
1651
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1743
    _fmt = ("The working tree for %(basedir)s has changed since"
1652
1744
            " the last commit, but weave merge requires that it be"
1653
1745
            " unchanged")
1654
1746
 
1816
1908
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1817
1909
 
1818
1910
    def __init__(self, from_path='', to_path='', extra=None):
 
1911
        from bzrlib.osutils import splitpath
1819
1912
        BzrError.__init__(self)
1820
1913
        if extra:
1821
1914
            self.extra = ': ' + str(extra)
1825
1918
        has_from = len(from_path) > 0
1826
1919
        has_to = len(to_path) > 0
1827
1920
        if has_from:
1828
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1921
            self.from_path = splitpath(from_path)[-1]
1829
1922
        else:
1830
1923
            self.from_path = ''
1831
1924
 
1832
1925
        if has_to:
1833
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1926
            self.to_path = splitpath(to_path)[-1]
1834
1927
        else:
1835
1928
            self.to_path = ''
1836
1929
 
1919
2012
 
1920
2013
class BadConversionTarget(BzrError):
1921
2014
 
1922
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2015
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2016
            "    %(problem)s"
1923
2017
 
1924
 
    def __init__(self, problem, format):
 
2018
    def __init__(self, problem, format, from_format=None):
1925
2019
        BzrError.__init__(self)
1926
2020
        self.problem = problem
1927
2021
        self.format = format
 
2022
        self.from_format = from_format or '(unspecified)'
1928
2023
 
1929
2024
 
1930
2025
class NoDiffFound(BzrError):
1967
2062
    _fmt = """This tree contains left-over files from a failed operation.
1968
2063
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1969
2064
    keep, and delete it when you are done."""
1970
 
    
 
2065
 
1971
2066
    def __init__(self, limbo_dir):
1972
2067
       BzrError.__init__(self)
1973
2068
       self.limbo_dir = limbo_dir
2006
2101
 
2007
2102
class OutOfDateTree(BzrError):
2008
2103
 
2009
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2104
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
2010
2105
 
2011
 
    def __init__(self, tree):
 
2106
    def __init__(self, tree, more=None):
 
2107
        if more is None:
 
2108
            more = ''
 
2109
        else:
 
2110
            more = ' ' + more
2012
2111
        BzrError.__init__(self)
2013
2112
        self.tree = tree
 
2113
        self.more = more
2014
2114
 
2015
2115
 
2016
2116
class PublicBranchOutOfDate(BzrError):
2070
2170
        self.reason = reason
2071
2171
 
2072
2172
 
 
2173
class InconsistentDeltaDelta(InconsistentDelta):
 
2174
    """Used when we get a delta that is not valid."""
 
2175
 
 
2176
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2177
            "\nreason: %(reason)s")
 
2178
 
 
2179
    def __init__(self, delta, reason):
 
2180
        BzrError.__init__(self)
 
2181
        self.delta = delta
 
2182
        self.reason = reason
 
2183
 
 
2184
 
2073
2185
class UpgradeRequired(BzrError):
2074
2186
 
2075
2187
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2084
2196
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2085
2197
 
2086
2198
 
 
2199
class RichRootUpgradeRequired(UpgradeRequired):
 
2200
 
 
2201
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2202
           " a format which supports rich roots.")
 
2203
 
 
2204
 
2087
2205
class LocalRequiresBoundBranch(BzrError):
2088
2206
 
2089
2207
    _fmt = "Cannot perform local-only commits on unbound branches."
2090
2208
 
2091
2209
 
2092
 
class MissingProgressBarFinish(BzrError):
2093
 
 
2094
 
    _fmt = "A nested progress bar was not 'finished' correctly."
2095
 
 
2096
 
 
2097
 
class InvalidProgressBarType(BzrError):
2098
 
 
2099
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2100
 
            " is not a supported type Select one of: %(valid_types)s")
2101
 
 
2102
 
    def __init__(self, bar_type, valid_types):
2103
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2104
 
 
2105
 
 
2106
2210
class UnsupportedOperation(BzrError):
2107
2211
 
2108
2212
    _fmt = ("The method %(mname)s is not supported on"
2125
2229
 
2126
2230
 
2127
2231
class BinaryFile(BzrError):
2128
 
    
 
2232
 
2129
2233
    _fmt = "File is binary but should be text."
2130
2234
 
2131
2235
 
2151
2255
 
2152
2256
 
2153
2257
class NotABundle(BzrError):
2154
 
    
 
2258
 
2155
2259
    _fmt = "Not a bzr revision-bundle: %(text)r"
2156
2260
 
2157
2261
    def __init__(self, text):
2159
2263
        self.text = text
2160
2264
 
2161
2265
 
2162
 
class BadBundle(BzrError): 
2163
 
    
 
2266
class BadBundle(BzrError):
 
2267
 
2164
2268
    _fmt = "Bad bzr revision-bundle: %(text)r"
2165
2269
 
2166
2270
    def __init__(self, text):
2168
2272
        self.text = text
2169
2273
 
2170
2274
 
2171
 
class MalformedHeader(BadBundle): 
2172
 
    
 
2275
class MalformedHeader(BadBundle):
 
2276
 
2173
2277
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2174
2278
 
2175
2279
 
2176
 
class MalformedPatches(BadBundle): 
2177
 
    
 
2280
class MalformedPatches(BadBundle):
 
2281
 
2178
2282
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2179
2283
 
2180
2284
 
2181
 
class MalformedFooter(BadBundle): 
2182
 
    
 
2285
class MalformedFooter(BadBundle):
 
2286
 
2183
2287
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2184
2288
 
2185
2289
 
2186
2290
class UnsupportedEOLMarker(BadBundle):
2187
 
    
2188
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2291
 
 
2292
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
2189
2293
 
2190
2294
    def __init__(self):
2191
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2295
        # XXX: BadBundle's constructor assumes there's explanatory text,
2192
2296
        # but for this there is not
2193
2297
        BzrError.__init__(self)
2194
2298
 
2195
2299
 
2196
2300
class IncompatibleBundleFormat(BzrError):
2197
 
    
 
2301
 
2198
2302
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2199
2303
 
2200
2304
    def __init__(self, bundle_format, other):
2204
2308
 
2205
2309
 
2206
2310
class BadInventoryFormat(BzrError):
2207
 
    
 
2311
 
2208
2312
    _fmt = "Root class for inventory serialization errors"
2209
2313
 
2210
2314
 
2229
2333
        self.transport = transport
2230
2334
 
2231
2335
 
2232
 
class NoSmartServer(NotBranchError):
2233
 
 
2234
 
    _fmt = "No smart server available at %(url)s"
2235
 
 
2236
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
2237
 
    def __init__(self, url):
2238
 
        self.url = url
2239
 
 
2240
 
 
2241
2336
class UnknownSSH(BzrError):
2242
2337
 
2243
2338
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2253
2348
            " Please set BZR_SSH environment variable.")
2254
2349
 
2255
2350
 
 
2351
class GhostRevisionsHaveNoRevno(BzrError):
 
2352
    """When searching for revnos, if we encounter a ghost, we are stuck"""
 
2353
 
 
2354
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
 
2355
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
 
2356
 
 
2357
    def __init__(self, revision_id, ghost_revision_id):
 
2358
        self.revision_id = revision_id
 
2359
        self.ghost_revision_id = ghost_revision_id
 
2360
 
 
2361
 
2256
2362
class GhostRevisionUnusableHere(BzrError):
2257
2363
 
2258
2364
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2336
2442
        self.patch_type = patch_type
2337
2443
 
2338
2444
 
 
2445
class TargetNotBranch(BzrError):
 
2446
    """A merge directive's target branch is required, but isn't a branch"""
 
2447
 
 
2448
    _fmt = ("Your branch does not have all of the revisions required in "
 
2449
            "order to merge this merge directive and the target "
 
2450
            "location specified in the merge directive is not a branch: "
 
2451
            "%(location)s.")
 
2452
 
 
2453
    def __init__(self, location):
 
2454
        BzrError.__init__(self)
 
2455
        self.location = location
 
2456
 
 
2457
 
2339
2458
class UnsupportedInventoryKind(BzrError):
2340
 
    
 
2459
 
2341
2460
    _fmt = """Unsupported entry kind %(kind)s"""
2342
2461
 
2343
2462
    def __init__(self, kind):
2355
2474
 
2356
2475
 
2357
2476
class SubsumeTargetNeedsUpgrade(BzrError):
2358
 
    
 
2477
 
2359
2478
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2360
2479
 
2361
2480
    def __init__(self, other_tree):
2384
2503
class TagsNotSupported(BzrError):
2385
2504
 
2386
2505
    _fmt = ("Tags not supported by %(branch)s;"
2387
 
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2506
            " you may be able to use bzr upgrade.")
2388
2507
 
2389
2508
    def __init__(self, branch):
2390
2509
        self.branch = branch
2391
2510
 
2392
 
        
 
2511
 
2393
2512
class TagAlreadyExists(BzrError):
2394
2513
 
2395
2514
    _fmt = "Tag %(tag_name)s already exists."
2400
2519
 
2401
2520
class MalformedBugIdentifier(BzrError):
2402
2521
 
2403
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2522
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2523
            'See "bzr help bugs" for more information on this feature.')
2404
2524
 
2405
2525
    def __init__(self, bug_id, reason):
2406
2526
        self.bug_id = bug_id
2427
2547
        self.branch = branch
2428
2548
 
2429
2549
 
 
2550
class InvalidLineInBugsProperty(BzrError):
 
2551
 
 
2552
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2553
 
 
2554
    def __init__(self, line):
 
2555
        self.line = line
 
2556
 
 
2557
 
 
2558
class InvalidBugStatus(BzrError):
 
2559
 
 
2560
    _fmt = ("Invalid bug status: '%(status)s'")
 
2561
 
 
2562
    def __init__(self, status):
 
2563
        self.status = status
 
2564
 
 
2565
 
2430
2566
class UnexpectedSmartServerResponse(BzrError):
2431
2567
 
2432
2568
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2436
2572
 
2437
2573
 
2438
2574
class ErrorFromSmartServer(BzrError):
 
2575
    """An error was received from a smart server.
 
2576
 
 
2577
    :seealso: UnknownErrorFromSmartServer
 
2578
    """
2439
2579
 
2440
2580
    _fmt = "Error received from smart server: %(error_tuple)r"
2441
2581
 
2450
2590
        self.error_args = error_tuple[1:]
2451
2591
 
2452
2592
 
 
2593
class UnknownErrorFromSmartServer(BzrError):
 
2594
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2595
    error.
 
2596
 
 
2597
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2598
    distinguish between the following two cases:
 
2599
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2600
        and so should provoke a traceback to the user.
 
2601
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2602
        translated.  This is probably because the server sent us garbage, and
 
2603
        should not provoke a traceback.
 
2604
    """
 
2605
 
 
2606
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2607
 
 
2608
    internal_error = False
 
2609
 
 
2610
    def __init__(self, error_from_smart_server):
 
2611
        """Constructor.
 
2612
 
 
2613
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2614
        """
 
2615
        self.error_from_smart_server = error_from_smart_server
 
2616
        self.error_tuple = error_from_smart_server.error_tuple
 
2617
 
 
2618
 
2453
2619
class ContainerError(BzrError):
2454
2620
    """Base class of container errors."""
2455
2621
 
2457
2623
class UnknownContainerFormatError(ContainerError):
2458
2624
 
2459
2625
    _fmt = "Unrecognised container format: %(container_format)r"
2460
 
    
 
2626
 
2461
2627
    def __init__(self, container_format):
2462
2628
        self.container_format = container_format
2463
2629
 
2527
2693
 
2528
2694
class NoMailAddressSpecified(BzrError):
2529
2695
 
2530
 
    _fmt = "No mail-to address specified."
 
2696
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2531
2697
 
2532
2698
 
2533
2699
class UnknownMailClient(BzrError):
2613
2779
    _fmt = "'%(display_url)s' is already standalone."
2614
2780
 
2615
2781
 
 
2782
class AlreadyWithTrees(BzrDirError):
 
2783
 
 
2784
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2785
            "working trees.")
 
2786
 
 
2787
 
 
2788
class AlreadyWithNoTrees(BzrDirError):
 
2789
 
 
2790
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2791
            "working trees.")
 
2792
 
 
2793
 
2616
2794
class ReconfigurationNotSupported(BzrDirError):
2617
2795
 
2618
2796
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2625
2803
 
2626
2804
class UncommittedChanges(BzrError):
2627
2805
 
2628
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2806
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2807
            ' (See bzr status).%(more)s')
2629
2808
 
2630
 
    def __init__(self, tree):
 
2809
    def __init__(self, tree, more=None):
 
2810
        if more is None:
 
2811
            more = ''
 
2812
        else:
 
2813
            more = ' ' + more
2631
2814
        import bzrlib.urlutils as urlutils
2632
2815
        display_url = urlutils.unescape_for_display(
2633
2816
            tree.bzrdir.root_transport.base, 'ascii')
2634
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2817
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2635
2818
 
2636
2819
 
2637
2820
class MissingTemplateVariable(BzrError):
2672
2855
 
2673
2856
 
2674
2857
class CommandAvailableInPlugin(StandardError):
2675
 
    
 
2858
 
2676
2859
    internal_error = False
2677
2860
 
2678
2861
    def __init__(self, cmd_name, plugin_metadata, provider):
2679
 
        
 
2862
 
2680
2863
        self.plugin_metadata = plugin_metadata
2681
2864
        self.cmd_name = cmd_name
2682
2865
        self.provider = provider
2683
2866
 
2684
2867
    def __str__(self):
2685
2868
 
2686
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2869
        _fmt = ('"%s" is not a standard bzr command. \n'
2687
2870
                'However, the following official plugin provides this command: %s\n'
2688
2871
                'You can install it by going to: %s'
2689
 
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2872
                % (self.cmd_name, self.plugin_metadata['name'],
2690
2873
                    self.plugin_metadata['url']))
2691
2874
 
2692
2875
        return _fmt
2693
2876
 
2694
2877
 
2695
2878
class NoPluginAvailable(BzrError):
2696
 
    pass    
2697
 
 
2698
 
 
2699
 
class NotATerminal(BzrError):
2700
 
 
2701
 
    _fmt = 'Unable to ask for a password without real terminal.'
 
2879
    pass
2702
2880
 
2703
2881
 
2704
2882
class UnableEncodePath(BzrError):
2707
2885
            'user encoding %(user_encoding)s')
2708
2886
 
2709
2887
    def __init__(self, path, kind):
 
2888
        from bzrlib.osutils import get_user_encoding
2710
2889
        self.path = path
2711
2890
        self.kind = kind
2712
2891
        self.user_encoding = osutils.get_user_encoding()
2713
2892
 
2714
2893
 
 
2894
class NoSuchAlias(BzrError):
 
2895
 
 
2896
    _fmt = ('The alias "%(alias_name)s" does not exist.')
 
2897
 
 
2898
    def __init__(self, alias_name):
 
2899
        BzrError.__init__(self, alias_name=alias_name)
 
2900
 
 
2901
 
 
2902
class DirectoryLookupFailure(BzrError):
 
2903
    """Base type for lookup errors."""
 
2904
 
 
2905
    pass
 
2906
 
 
2907
 
 
2908
class InvalidLocationAlias(DirectoryLookupFailure):
 
2909
 
 
2910
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2911
 
 
2912
    def __init__(self, alias_name):
 
2913
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2914
 
 
2915
 
 
2916
class UnsetLocationAlias(DirectoryLookupFailure):
 
2917
 
 
2918
    _fmt = 'No %(alias_name)s location assigned.'
 
2919
 
 
2920
    def __init__(self, alias_name):
 
2921
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2922
 
 
2923
 
2715
2924
class CannotBindAddress(BzrError):
2716
2925
 
2717
2926
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2718
2927
 
2719
2928
    def __init__(self, host, port, orig_error):
 
2929
        # nb: in python2.4 socket.error doesn't have a useful repr
2720
2930
        BzrError.__init__(self, host=host, port=port,
2721
 
            orig_error=orig_error[1])
 
2931
            orig_error=repr(orig_error.args))
 
2932
 
 
2933
 
 
2934
class UnknownRules(BzrError):
 
2935
 
 
2936
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
2937
 
 
2938
    def __init__(self, unknowns):
 
2939
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
2940
 
 
2941
 
 
2942
class HookFailed(BzrError):
 
2943
    """Raised when a pre_change_branch_tip hook function fails anything other
 
2944
    than TipChangeRejected.
 
2945
    """
 
2946
 
 
2947
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
2948
            "%(traceback_text)s%(exc_value)s")
 
2949
 
 
2950
    def __init__(self, hook_stage, hook_name, exc_info):
 
2951
        import traceback
 
2952
        self.hook_stage = hook_stage
 
2953
        self.hook_name = hook_name
 
2954
        self.exc_info = exc_info
 
2955
        self.exc_type = exc_info[0]
 
2956
        self.exc_value = exc_info[1]
 
2957
        self.exc_tb = exc_info[2]
 
2958
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
 
2959
 
 
2960
 
 
2961
class TipChangeRejected(BzrError):
 
2962
    """A pre_change_branch_tip hook function may raise this to cleanly and
 
2963
    explicitly abort a change to a branch tip.
 
2964
    """
 
2965
 
 
2966
    _fmt = u"Tip change rejected: %(msg)s"
 
2967
 
 
2968
    def __init__(self, msg):
 
2969
        self.msg = msg
 
2970
 
 
2971
 
 
2972
class ShelfCorrupt(BzrError):
 
2973
 
 
2974
    _fmt = "Shelf corrupt."
 
2975
 
 
2976
 
 
2977
class NoSuchShelfId(BzrError):
 
2978
 
 
2979
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
2980
 
 
2981
    def __init__(self, shelf_id):
 
2982
        BzrError.__init__(self, shelf_id=shelf_id)
 
2983
 
 
2984
 
 
2985
class InvalidShelfId(BzrError):
 
2986
 
 
2987
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
2988
 
 
2989
    def __init__(self, invalid_id):
 
2990
        BzrError.__init__(self, invalid_id=invalid_id)
 
2991
 
 
2992
 
 
2993
class JailBreak(BzrError):
 
2994
 
 
2995
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
2996
 
 
2997
    def __init__(self, url):
 
2998
        BzrError.__init__(self, url=url)
 
2999
 
 
3000
 
 
3001
class UserAbort(BzrError):
 
3002
 
 
3003
    _fmt = 'The user aborted the operation.'
 
3004
 
 
3005
 
 
3006
class MustHaveWorkingTree(BzrError):
 
3007
 
 
3008
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3009
 
 
3010
    def __init__(self, format, url):
 
3011
        BzrError.__init__(self, format=format, url=url)
 
3012
 
 
3013
 
 
3014
class NoSuchView(BzrError):
 
3015
    """A view does not exist.
 
3016
    """
 
3017
 
 
3018
    _fmt = u"No such view: %(view_name)s."
 
3019
 
 
3020
    def __init__(self, view_name):
 
3021
        self.view_name = view_name
 
3022
 
 
3023
 
 
3024
class ViewsNotSupported(BzrError):
 
3025
    """Views are not supported by a tree format.
 
3026
    """
 
3027
 
 
3028
    _fmt = ("Views are not supported by %(tree)s;"
 
3029
            " use 'bzr upgrade' to change your tree to a later format.")
 
3030
 
 
3031
    def __init__(self, tree):
 
3032
        self.tree = tree
 
3033
 
 
3034
 
 
3035
class FileOutsideView(BzrError):
 
3036
 
 
3037
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3038
            '%(view_str)s')
 
3039
 
 
3040
    def __init__(self, file_name, view_files):
 
3041
        self.file_name = file_name
 
3042
        self.view_str = ", ".join(view_files)
 
3043
 
 
3044
 
 
3045
class UnresumableWriteGroup(BzrError):
 
3046
 
 
3047
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3048
            "%(write_groups)r: %(reason)s")
 
3049
 
 
3050
    internal_error = True
 
3051
 
 
3052
    def __init__(self, repository, write_groups, reason):
 
3053
        self.repository = repository
 
3054
        self.write_groups = write_groups
 
3055
        self.reason = reason
 
3056
 
 
3057
 
 
3058
class UnsuspendableWriteGroup(BzrError):
 
3059
 
 
3060
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3061
 
 
3062
    internal_error = True
 
3063
 
 
3064
    def __init__(self, repository):
 
3065
        self.repository = repository
 
3066
 
 
3067
 
 
3068
class LossyPushToSameVCS(BzrError):
 
3069
 
 
3070
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3071
            "%(target_branch)r that are in the same VCS.")
 
3072
 
 
3073
    internal_error = True
 
3074
 
 
3075
    def __init__(self, source_branch, target_branch):
 
3076
        self.source_branch = source_branch
 
3077
        self.target_branch = target_branch