~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2006-11-02 10:20:19 UTC
  • mfrom: (2114 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2119.
  • Revision ID: mbp@sourcefrog.net-20061102102019-9a5a02f485dff6f6
merge bzr.dev and reconcile several changes, also some test fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
111
111
        fmt = getattr(self, '_fmt', None)
112
112
        if fmt is not None:
113
113
            return fmt
114
 
        fmt = getAttr(self, '__doc__', None)
 
114
        fmt = getattr(self, '__doc__', None)
115
115
        if fmt is not None:
116
 
            symbol_versioning.warn("%s uses it's docstring as a format, "
117
 
                    "it should use _fmt instead" % self.__class__.__name__)
 
116
            symbol_versioning.warn("%s uses its docstring as a format, "
 
117
                    "it should use _fmt instead" % self.__class__.__name__,
 
118
                    DeprecationWarning)
118
119
            # TODO: This should be deprecated when all exceptions have
119
120
            # been changed not to rely on this.
120
 
            return 'Unprintable exception %s: dict=%r, fmt=%r' \
121
 
                % (self.__class__.__name__,
122
 
                   self.__dict__,
123
 
                   getattr(self, '_fmt', None),
124
 
                   )
 
121
            return fmt
 
122
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
 
123
            % (self.__class__.__name__,
 
124
               self.__dict__,
 
125
               getattr(self, '_fmt', None),
 
126
               )
125
127
 
126
128
 
127
129
class BzrNewError(BzrError):
213
215
        self.tree = tree
214
216
 
215
217
 
 
218
class InventoryModified(BzrError):
 
219
 
 
220
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
 
221
            "so a clean inventory cannot be read without data loss.")
 
222
 
 
223
    internal_error = True
 
224
 
 
225
    def __init__(self, tree):
 
226
        self.tree = tree
 
227
 
 
228
 
216
229
class NoWorkingTree(BzrError):
217
230
 
218
231
    _fmt = "No WorkingTree exists for %(base)s."
230
243
class NotLocalUrl(BzrError):
231
244
 
232
245
    _fmt = "%(url)s is not a local path."
233
 
    
 
246
 
234
247
    def __init__(self, url):
235
 
        BzrError.__init__(self)
236
248
        self.url = url
237
249
 
238
250
 
 
251
class WorkingTreeAlreadyPopulated(BzrError):
 
252
 
 
253
    _fmt = """Working tree already populated in %(base)s"""
 
254
 
 
255
    internal_error = True
 
256
 
 
257
    def __init__(self, base):
 
258
        self.base = base
 
259
 
239
260
class BzrCommandError(BzrError):
240
261
    """Error from user command"""
241
262
 
260
281
        return self.msg
261
282
 
262
283
 
 
284
class NotWriteLocked(BzrError):
 
285
 
 
286
    _fmt = """%(not_locked)r is not write locked but needs to be."""
 
287
 
 
288
    def __init__(self, not_locked):
 
289
        self.not_locked = not_locked
 
290
 
 
291
 
263
292
class BzrOptionError(BzrCommandError):
264
293
 
265
294
    _fmt = "Error in command line options"
300
329
    _fmt = "Directory not empty: %(path)r%(extra)s"
301
330
 
302
331
 
 
332
class ReadingCompleted(BzrError):
 
333
    
 
334
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
 
335
            "called upon it - the request has been completed and no more "
 
336
            "data may be read.")
 
337
 
 
338
    internal_error = True
 
339
 
 
340
    def __init__(self, request):
 
341
        self.request = request
 
342
 
 
343
 
303
344
class ResourceBusy(PathError):
304
345
 
305
346
    _fmt = "Device or resource busy: %(path)r%(extra)s"
937
978
        BzrError.__init__(self)
938
979
 
939
980
 
 
981
class TooManyConcurrentRequests(BzrError):
 
982
 
 
983
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
 
984
            "Be sure to finish_writing and finish_reading on the "
 
985
            "current request that is open.")
 
986
 
 
987
    internal_error = True
 
988
 
 
989
    def __init__(self, medium):
 
990
        self.medium = medium
 
991
 
 
992
 
940
993
class SmartProtocolError(TransportError):
941
994
 
942
995
    _fmt = "Generic bzr smart protocol error: %(details)s"
956
1009
    _fmt = "Connection error: %(msg)s %(orig_error)s"
957
1010
 
958
1011
 
 
1012
class SocketConnectionError(ConnectionError):
 
1013
 
 
1014
    _fmt = "%(msg)s %(host)s%(port)s%(orig_error)s"
 
1015
 
 
1016
    def __init__(self, host, port=None, msg=None, orig_error=None):
 
1017
        if msg is None:
 
1018
            msg = 'Failed to connect to'
 
1019
        if orig_error is None:
 
1020
            orig_error = ''
 
1021
        else:
 
1022
            orig_error = '; ' + str(orig_error)
 
1023
        ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
 
1024
        self.host = host
 
1025
        if port is None:
 
1026
            self.port = ''
 
1027
        else:
 
1028
            self.port = ':%s' % port
 
1029
 
 
1030
 
959
1031
class ConnectionReset(TransportError):
960
1032
 
961
1033
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1056
1128
        self.graph = graph
1057
1129
 
1058
1130
 
 
1131
class WritingCompleted(BzrError):
 
1132
 
 
1133
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
 
1134
            "called upon it - accept bytes may not be called anymore.")
 
1135
 
 
1136
    internal_error = True
 
1137
 
 
1138
    def __init__(self, request):
 
1139
        self.request = request
 
1140
 
 
1141
 
 
1142
class WritingNotComplete(BzrError):
 
1143
 
 
1144
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
 
1145
            "called upon it - until the write phase is complete no "
 
1146
            "data may be read.")
 
1147
 
 
1148
    internal_error = True
 
1149
 
 
1150
    def __init__(self, request):
 
1151
        self.request = request
 
1152
 
 
1153
 
1059
1154
class NotConflicted(BzrError):
1060
1155
 
1061
1156
    _fmt = "File %(filename)s is not conflicted."
1065
1160
        self.filename = filename
1066
1161
 
1067
1162
 
 
1163
class MediumNotConnected(BzrError):
 
1164
 
 
1165
    _fmt = """The medium '%(medium)s' is not connected."""
 
1166
 
 
1167
    internal_error = True
 
1168
 
 
1169
    def __init__(self, medium):
 
1170
        self.medium = medium
 
1171
 
 
1172
 
1068
1173
class MustUseDecorated(Exception):
1069
1174
    
1070
1175
    _fmt = """A decorating function has requested its original command be used."""
1111
1216
    _fmt = "Tree transform is malformed %(conflicts)r"
1112
1217
 
1113
1218
 
 
1219
class NoFinalPath(BzrError):
 
1220
 
 
1221
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1222
            "file-id: %(file_id)r\n"
 
1223
            "root trans-id: %(root_trans_id)r\n")
 
1224
 
 
1225
    def __init__(self, trans_id, transform):
 
1226
        self.trans_id = trans_id
 
1227
        self.file_id = transform.final_file_id(trans_id)
 
1228
        self.root_trans_id = transform.root
 
1229
 
 
1230
 
1114
1231
class BzrBadParameter(BzrError):
1115
1232
 
1116
1233
    _fmt = "Bad parameter: %(param)r"
1117
 
    
 
1234
 
1118
1235
    # This exception should never be thrown, but it is a base class for all
1119
1236
    # parameter-to-function errors.
1120
1237
 
1392
1509
        BadInventoryFormat.__init__(self, msg=msg)
1393
1510
 
1394
1511
 
 
1512
class NoSmartMedium(BzrError):
 
1513
 
 
1514
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
 
1515
 
 
1516
    def __init__(self, transport):
 
1517
        self.transport = transport
 
1518
 
 
1519
 
1395
1520
class NoSmartServer(NotBranchError):
1396
1521
 
1397
1522
    _fmt = "No smart server available at %(url)s"