/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

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
# 'unprintable'.
45
45
 
46
46
 
 
47
# return codes from the bzr program
 
48
EXIT_OK = 0
 
49
EXIT_ERROR = 3
 
50
EXIT_INTERNAL_ERROR = 4
 
51
 
 
52
 
47
53
class BzrError(StandardError):
48
54
    """
49
55
    Base class for errors raised by bzrlib.
95
101
        try:
96
102
            fmt = self._get_format_string()
97
103
            if fmt:
98
 
                s = fmt % self.__dict__
 
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
                s = fmt % d
99
109
                # __str__() should always return a 'str' object
100
110
                # never a 'unicode' object.
101
111
                if isinstance(s, unicode):
126
136
               )
127
137
 
128
138
 
 
139
class InternalBzrError(BzrError):
 
140
    """Base class for errors that are internal in nature.
 
141
 
 
142
    This is a convenience class for errors that are internal. The
 
143
    internal_error attribute can still be altered in subclasses, if needed.
 
144
    Using this class is simply an easy way to get internal errors.
 
145
    """
 
146
 
 
147
    internal_error = True
 
148
 
 
149
 
129
150
class BzrNewError(BzrError):
130
151
    """Deprecated error base class."""
131
152
    # base classes should override the docstring with their human-
164
185
    _fmt = "The tree builder is already building a tree."
165
186
 
166
187
 
167
 
class BzrCheckError(BzrError):
 
188
class BzrCheckError(InternalBzrError):
168
189
    
169
190
    _fmt = "Internal check failed: %(message)s"
170
191
 
171
 
    internal_error = True
172
 
 
173
192
    def __init__(self, message):
174
193
        BzrError.__init__(self)
175
194
        self.message = message
176
195
 
177
196
 
178
 
class DisabledMethod(BzrError):
 
197
class DisabledMethod(InternalBzrError):
179
198
 
180
199
    _fmt = "The smart server method '%(class_name)s' is disabled."
181
200
 
182
 
    internal_error = True
183
 
 
184
201
    def __init__(self, class_name):
185
202
        BzrError.__init__(self)
186
203
        self.class_name = class_name
207
224
        self.transport = transport
208
225
 
209
226
 
210
 
class InvalidEntryName(BzrError):
 
227
class InvalidEntryName(InternalBzrError):
211
228
    
212
229
    _fmt = "Invalid entry name: %(name)s"
213
230
 
214
 
    internal_error = True
215
 
 
216
231
    def __init__(self, name):
217
232
        BzrError.__init__(self)
218
233
        self.name = name
245
260
        self.revision_id = revision_id
246
261
 
247
262
 
 
263
class RootMissing(InternalBzrError):
 
264
 
 
265
    _fmt = ("The root entry of a tree must be the first entry supplied to "
 
266
        "record_entry_contents.")
 
267
 
 
268
 
248
269
class NoHelpTopic(BzrError):
249
270
 
250
271
    _fmt = ("No help could be found for '%(topic)s'. "
273
294
        BzrError.__init__(self, repository=repository, file_id=file_id)
274
295
 
275
296
 
276
 
class InventoryModified(BzrError):
 
297
class InventoryModified(InternalBzrError):
277
298
 
278
299
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
279
300
            " so a clean inventory cannot be read without data loss.")
280
301
 
281
 
    internal_error = True
282
 
 
283
302
    def __init__(self, tree):
284
303
        self.tree = tree
285
304
 
306
325
        self.url = url
307
326
 
308
327
 
309
 
class WorkingTreeAlreadyPopulated(BzrError):
 
328
class WorkingTreeAlreadyPopulated(InternalBzrError):
310
329
 
311
330
    _fmt = 'Working tree already populated in "%(base)s"'
312
331
 
313
 
    internal_error = True
314
 
 
315
332
    def __init__(self, base):
316
333
        self.base = base
317
334
 
 
335
 
318
336
class BzrCommandError(BzrError):
319
337
    """Error from user command"""
320
338
 
321
 
    internal_error = False
322
 
 
323
339
    # Error from malformed user command; please avoid raising this as a
324
340
    # generic exception not caused by user input.
325
341
    #
481
497
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
482
498
 
483
499
 
484
 
class ReadingCompleted(BzrError):
 
500
class ReadingCompleted(InternalBzrError):
485
501
    
486
502
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
487
503
            "called upon it - the request has been completed and no more "
488
504
            "data may be read.")
489
505
 
490
 
    internal_error = True
491
 
 
492
506
    def __init__(self, request):
493
507
        self.request = request
494
508
 
770
784
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
771
785
 
772
786
 
773
 
class LockError(BzrError):
 
787
class LockError(InternalBzrError):
774
788
 
775
789
    _fmt = "Lock error: %(msg)s"
776
790
 
777
 
    internal_error = True
778
 
 
779
791
    # All exceptions from the lock/unlock functions should be from
780
792
    # this exception class.  They will be translated as necessary. The
781
793
    # original exception is available as e.original_error
783
795
    # New code should prefer to raise specific subclasses
784
796
    def __init__(self, message):
785
797
        # Python 2.5 uses a slot for StandardError.message,
786
 
        # so use a different variable name
787
 
        # so it is exposed in self.__dict__
 
798
        # so use a different variable name.  We now work around this in
 
799
        # BzrError.__str__, but this member name is kept for compatability.
788
800
        self.msg = message
789
801
 
790
802
 
829
841
 
830
842
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
831
843
 
 
844
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
832
845
    def __init__(self, fname, msg):
833
846
        LockError.__init__(self, '')
834
847
        self.fname = fname
835
848
        self.msg = msg
836
849
 
837
850
 
 
851
class LockFailed(LockError):
 
852
 
 
853
    internal_error = False
 
854
 
 
855
    _fmt = "Cannot lock %(lock)s: %(why)s"
 
856
 
 
857
    def __init__(self, lock, why):
 
858
        LockError.__init__(self, '')
 
859
        self.lock = lock
 
860
        self.why = why
 
861
 
 
862
 
838
863
class OutSideTransaction(BzrError):
839
864
 
840
865
    _fmt = ("A transaction related operation was attempted after"
862
887
 
863
888
class UnlockableTransport(LockError):
864
889
 
 
890
    internal_error = False
 
891
 
865
892
    _fmt = "Cannot lock: transport is read only: %(transport)s"
866
893
 
867
894
    def __init__(self, transport):
918
945
 
919
946
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
920
947
 
921
 
    internal_error = True
922
 
 
923
948
    def __init__(self, obj):
924
949
        self.obj = obj
925
950
 
975
1000
    _fmt = "Commit refused because there are unknowns in the tree."
976
1001
 
977
1002
 
978
 
class NoSuchRevision(BzrError):
 
1003
class NoSuchRevision(InternalBzrError):
979
1004
 
980
1005
    _fmt = "%(branch)s has no revision %(revision)s"
981
1006
 
982
 
    internal_error = True
983
 
 
984
1007
    def __init__(self, branch, revision):
985
1008
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
986
1009
        BzrError.__init__(self, branch=branch, revision=revision)
987
1010
 
988
1011
 
989
1012
# zero_ninetyone: this exception is no longer raised and should be removed
990
 
class NotLeftParentDescendant(BzrError):
 
1013
class NotLeftParentDescendant(InternalBzrError):
991
1014
 
992
1015
    _fmt = ("Revision %(old_revision)s is not the left parent of"
993
1016
            " %(new_revision)s, but branch %(branch_location)s expects this")
994
1017
 
995
 
    internal_error = True
996
 
 
997
1018
    def __init__(self, branch, old_revision, new_revision):
998
1019
        BzrError.__init__(self, branch_location=branch.base,
999
1020
                          old_revision=old_revision,
1059
1080
    _fmt = ("These branches have diverged."
1060
1081
            " Use the merge command to reconcile them.")
1061
1082
 
1062
 
    internal_error = False
1063
 
 
1064
1083
    def __init__(self, branch1, branch2):
1065
1084
        self.branch1 = branch1
1066
1085
        self.branch2 = branch2
1067
1086
 
1068
1087
 
1069
 
class NotLefthandHistory(BzrError):
 
1088
class NotLefthandHistory(InternalBzrError):
1070
1089
 
1071
1090
    _fmt = "Supplied history does not follow left-hand parents"
1072
1091
 
1073
 
    internal_error = True
1074
 
 
1075
1092
    def __init__(self, history):
1076
1093
        BzrError.__init__(self, history=history)
1077
1094
 
1081
1098
    _fmt = ("Branches have no common ancestor, and"
1082
1099
            " no merge base revision was specified.")
1083
1100
 
1084
 
    internal_error = False
1085
 
 
1086
1101
 
1087
1102
class NoCommonAncestor(BzrError):
1088
1103
    
1299
1314
    _fmt = "Text did not match its checksum: %(message)s"
1300
1315
 
1301
1316
 
1302
 
class KnitError(BzrError):
 
1317
class KnitError(InternalBzrError):
1303
1318
    
1304
1319
    _fmt = "Knit error"
1305
1320
 
1306
 
    internal_error = True
1307
 
 
1308
1321
 
1309
1322
class KnitCorrupt(KnitError):
1310
1323
 
1374
1387
        BzrError.__init__(self)
1375
1388
 
1376
1389
 
1377
 
class TooManyConcurrentRequests(BzrError):
 
1390
class TooManyConcurrentRequests(InternalBzrError):
1378
1391
 
1379
1392
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1380
1393
            " Be sure to finish_writing and finish_reading on the"
1381
1394
            " currently open request.")
1382
1395
 
1383
 
    internal_error = True
1384
 
 
1385
1396
    def __init__(self, medium):
1386
1397
        self.medium = medium
1387
1398
 
1577
1588
        self.graph = graph
1578
1589
 
1579
1590
 
1580
 
class WritingCompleted(BzrError):
 
1591
class WritingCompleted(InternalBzrError):
1581
1592
 
1582
1593
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1583
1594
            "called upon it - accept bytes may not be called anymore.")
1584
1595
 
1585
 
    internal_error = True
1586
 
 
1587
1596
    def __init__(self, request):
1588
1597
        self.request = request
1589
1598
 
1590
1599
 
1591
 
class WritingNotComplete(BzrError):
 
1600
class WritingNotComplete(InternalBzrError):
1592
1601
 
1593
1602
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1594
1603
            "called upon it - until the write phase is complete no "
1595
1604
            "data may be read.")
1596
1605
 
1597
 
    internal_error = True
1598
 
 
1599
1606
    def __init__(self, request):
1600
1607
        self.request = request
1601
1608
 
1609
1616
        self.filename = filename
1610
1617
 
1611
1618
 
1612
 
class MediumNotConnected(BzrError):
 
1619
class MediumNotConnected(InternalBzrError):
1613
1620
 
1614
1621
    _fmt = """The medium '%(medium)s' is not connected."""
1615
1622
 
1616
 
    internal_error = True
1617
 
 
1618
1623
    def __init__(self, medium):
1619
1624
        self.medium = medium
1620
1625
 
1696
1701
        self.root_trans_id = transform.root
1697
1702
 
1698
1703
 
1699
 
class BzrBadParameter(BzrError):
 
1704
class BzrBadParameter(InternalBzrError):
1700
1705
 
1701
1706
    _fmt = "Bad parameter: %(param)r"
1702
1707
 
1703
 
    internal_error = True
1704
 
 
1705
1708
    # This exception should never be thrown, but it is a base class for all
1706
1709
    # parameter-to-function errors.
1707
1710
 
1854
1857
    _fmt = "Diff3 is not installed on this machine."
1855
1858
 
1856
1859
 
 
1860
class ExistingContent(BzrError):
 
1861
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
1862
 
 
1863
    _fmt = "The content being inserted is already present."
 
1864
 
 
1865
 
1857
1866
class ExistingLimbo(BzrError):
1858
1867
 
1859
1868
    _fmt = """This tree contains left-over files from a failed operation.
2084
2093
    _fmt = """This operation requires rich root data storage"""
2085
2094
 
2086
2095
 
2087
 
class NoSmartMedium(BzrError):
 
2096
class NoSmartMedium(InternalBzrError):
2088
2097
 
2089
2098
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2090
2099
 
2091
 
    internal_error = True
2092
 
 
2093
2100
    def __init__(self, transport):
2094
2101
        self.transport = transport
2095
2102
 
2126
2133
        self.revision_id = revision_id
2127
2134
 
2128
2135
 
2129
 
class IllegalUseOfScopeReplacer(BzrError):
 
2136
class IllegalUseOfScopeReplacer(InternalBzrError):
2130
2137
 
2131
2138
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2132
2139
            " %(msg)s%(extra)s")
2133
2140
 
2134
 
    internal_error = True
2135
 
 
2136
2141
    def __init__(self, name, msg, extra=None):
2137
2142
        BzrError.__init__(self)
2138
2143
        self.name = name
2143
2148
            self.extra = ''
2144
2149
 
2145
2150
 
2146
 
class InvalidImportLine(BzrError):
 
2151
class InvalidImportLine(InternalBzrError):
2147
2152
 
2148
2153
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2149
2154
 
2150
 
    internal_error = True
2151
 
 
2152
2155
    def __init__(self, text, msg):
2153
2156
        BzrError.__init__(self)
2154
2157
        self.text = text
2155
2158
        self.msg = msg
2156
2159
 
2157
2160
 
2158
 
class ImportNameCollision(BzrError):
 
2161
class ImportNameCollision(InternalBzrError):
2159
2162
 
2160
2163
    _fmt = ("Tried to import an object to the same name as"
2161
2164
            " an existing object. %(name)s")
2162
2165
 
2163
 
    internal_error = True
2164
 
 
2165
2166
    def __init__(self, name):
2166
2167
        BzrError.__init__(self)
2167
2168
        self.name = name
2199
2200
class PatchMissing(BzrError):
2200
2201
    """Raise a patch type was specified but no patch supplied"""
2201
2202
 
2202
 
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
 
2203
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2203
2204
 
2204
2205
    def __init__(self, patch_type):
2205
2206
        BzrError.__init__(self)
2232
2233
        self.other_tree = other_tree
2233
2234
 
2234
2235
 
2235
 
class BadReferenceTarget(BzrError):
 
2236
class BadReferenceTarget(InternalBzrError):
2236
2237
 
2237
2238
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2238
2239
           "%(reason)s"
2239
2240
 
2240
 
    internal_error = True
2241
 
 
2242
2241
    def __init__(self, tree, other_tree, reason):
2243
2242
        self.tree = tree
2244
2243
        self.other_tree = other_tree
2313
2312
 
2314
2313
    _fmt = "Unexpected end of container stream"
2315
2314
 
2316
 
    internal_error = False
2317
 
 
2318
2315
 
2319
2316
class UnknownRecordTypeError(ContainerError):
2320
2317
 
2348
2345
        self.name = name
2349
2346
 
2350
2347
 
2351
 
class NoDestinationAddress(BzrError):
 
2348
class NoDestinationAddress(InternalBzrError):
2352
2349
 
2353
2350
    _fmt = "Message does not have a destination address."
2354
2351
 
2355
 
    internal_error = True
 
2352
 
 
2353
class RepositoryDataStreamError(BzrError):
 
2354
 
 
2355
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
 
2356
 
 
2357
    def __init__(self, reason):
 
2358
        self.reason = reason
2356
2359
 
2357
2360
 
2358
2361
class SMTPError(BzrError):
2398
2401
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2399
2402
 
2400
2403
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2404
 
 
2405
 
 
2406
class BzrDirError(BzrError):
 
2407
 
 
2408
    def __init__(self, bzrdir):
 
2409
        import bzrlib.urlutils as urlutils
 
2410
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2411
                                                    'ascii')
 
2412
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2413
 
 
2414
 
 
2415
class AlreadyBranch(BzrDirError):
 
2416
 
 
2417
    _fmt = "'%(display_url)s' is already a branch."
 
2418
 
 
2419
 
 
2420
class AlreadyTree(BzrDirError):
 
2421
 
 
2422
    _fmt = "'%(display_url)s' is already a tree."
 
2423
 
 
2424
 
 
2425
class AlreadyCheckout(BzrDirError):
 
2426
 
 
2427
    _fmt = "'%(display_url)s' is already a checkout."
 
2428
 
 
2429
 
 
2430
class ReconfigurationNotSupported(BzrDirError):
 
2431
 
 
2432
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2433
 
 
2434
 
 
2435
class NoBindLocation(BzrDirError):
 
2436
 
 
2437
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2438
 
 
2439
 
 
2440
class UncommittedChanges(BzrError):
 
2441
 
 
2442
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2443
 
 
2444
    def __init__(self, tree):
 
2445
        import bzrlib.urlutils as urlutils
 
2446
        display_url = urlutils.unescape_for_display(
 
2447
            tree.bzrdir.root_transport.base, 'ascii')
 
2448
        BzrError.__init__(self, tree=tree, display_url=display_url)