~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2006-08-01 04:54:43 UTC
  • mfrom: (1864.6.1 plugin-imports)
  • mto: This revision was merged to the branch mainline in revision 1901.
  • Revision ID: robertc@robertcollins.net-20060801045443-b99468f4250e01c4
Merge Johns bug 51810 fixup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
 
127
127
    def __str__(self):
128
128
        try:
129
 
            # __str__() should always return a 'str' object
130
 
            # never a 'unicode' object.
131
 
            s = self.__doc__ % self.__dict__
132
 
            if isinstance(s, unicode):
133
 
                return s.encode('utf8')
134
 
            return s
135
 
        except (TypeError, NameError, ValueError, KeyError), e:
136
 
            return 'Unprintable exception %s(%r): %s' \
137
 
                % (self.__class__.__name__,
138
 
                   self.__dict__, str(e))
 
129
            return self.__doc__ % self.__dict__
 
130
        except (NameError, ValueError, KeyError), e:
 
131
            return 'Unprintable exception %s: %s' \
 
132
                % (self.__class__.__name__, str(e))
139
133
 
140
134
 
141
135
class BzrCheckError(BzrNewError):
167
161
 
168
162
class InvalidRevisionId(BzrNewError):
169
163
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
170
 
 
171
164
    def __init__(self, revision_id, branch):
172
165
        # branch can be any string or object with __str__ defined
173
166
        BzrNewError.__init__(self)
175
168
        self.branch = branch
176
169
 
177
170
 
178
 
class NoSuchId(BzrNewError):
179
 
    """The file id %(file_id)s is not present in the tree %(tree)s."""
180
 
    
181
 
    def __init__(self, tree, file_id):
182
 
        BzrNewError.__init__(self)
183
 
        self.file_id = file_id
184
 
        self.tree = tree
185
 
 
186
 
 
187
171
class NoWorkingTree(BzrNewError):
188
172
    """No WorkingTree exists for %(base)s."""
189
173
    
213
197
    # BzrCommandError, and non-UI code should not throw a subclass of
214
198
    # BzrCommandError.  ADHB 20051211
215
199
    def __init__(self, msg):
216
 
        # Object.__str__() must return a real string
217
 
        # returning a Unicode string is a python error.
218
 
        if isinstance(msg, unicode):
219
 
            self.msg = msg.encode('utf8')
220
 
        else:
221
 
            self.msg = msg
 
200
        self.msg = msg
222
201
 
223
202
    def __str__(self):
224
203
        return self.msg
325
304
(use bzr checkout if you wish to build a working tree): %(path)s"""
326
305
 
327
306
 
328
 
class AtomicFileAlreadyClosed(PathError):
329
 
    """'%(function)s' called on an AtomicFile after it was closed: %(path)s"""
330
 
 
331
 
    def __init__(self, path, function):
332
 
        PathError.__init__(self, path=path, extra=None)
333
 
        self.function = function
334
 
 
335
 
 
336
 
class InaccessibleParent(PathError):
337
 
    """Parent not accessible given base %(base)s and relative path %(path)s"""
338
 
 
339
 
    def __init__(self, path, base):
340
 
        PathError.__init__(self, path)
341
 
        self.base = base
342
 
 
343
 
 
344
307
class NoRepositoryPresent(BzrNewError):
345
308
    """No repository present: %(path)r"""
346
309
    def __init__(self, bzrdir):
515
478
        self.format = format
516
479
 
517
480
 
 
481
 
518
482
class StrictCommitFailed(Exception):
519
483
    """Commit refused because there are unknowns in the tree."""
520
484
 
525
489
    is_user_error = False
526
490
 
527
491
    def __init__(self, branch, revision):
528
 
        BzrNewError.__init__(self, branch=branch, revision=revision)
529
 
 
530
 
 
531
 
class NoSuchRevisionSpec(BzrNewError):
532
 
    """No namespace registered for string: %(spec)r"""
533
 
 
534
 
    def __init__(self, spec):
535
 
        BzrNewError.__init__(self, spec=spec)
536
 
 
537
 
 
538
 
class InvalidRevisionSpec(BzrNewError):
539
 
    """Requested revision: '%(spec)s' does not exist in branch:
540
 
%(branch)s%(extra)s"""
541
 
 
542
 
    def __init__(self, spec, branch, extra=None):
543
 
        BzrNewError.__init__(self, branch=branch, spec=spec)
544
 
        if extra:
545
 
            self.extra = '\n' + str(extra)
546
 
        else:
547
 
            self.extra = ''
 
492
        self.branch = branch
 
493
        self.revision = revision
548
494
 
549
495
 
550
496
class HistoryMissing(BzrError):
613
559
        self.bases = bases
614
560
 
615
561
 
616
 
class NoCommits(BzrNewError):
617
 
    """Branch %(branch)s has no commits."""
618
 
 
 
562
class NoCommits(BzrError):
619
563
    def __init__(self, branch):
620
 
        BzrNewError.__init__(self, branch=branch)
 
564
        msg = "Branch %s has no commits." % branch
 
565
        BzrError.__init__(self, msg)
621
566
 
622
567
 
623
568
class UnlistableStore(BzrError):
791
736
        BzrNewError.__init__(self)
792
737
 
793
738
 
794
 
class SmartProtocolError(TransportError):
795
 
    """Generic bzr smart protocol error: %(details)s"""
796
 
 
797
 
    def __init__(self, details):
798
 
        self.details = details
799
 
 
800
 
 
801
739
# A set of semi-meaningful errors which can be thrown
802
740
class TransportNotPossible(TransportError):
803
741
    """Transport operation not possible: %(msg)s %(orig_error)%"""
812
750
 
813
751
 
814
752
class InvalidRange(TransportError):
815
 
    """Invalid range access in %(path)s at %(offset)s."""
 
753
    """Invalid range access."""
816
754
    
817
755
    def __init__(self, path, offset):
818
756
        TransportError.__init__(self, ("Invalid range access in %s at %d"
819
757
                                       % (path, offset)))
820
 
        self.path = path
821
 
        self.offset = offset
822
758
 
823
759
 
824
760
class InvalidHttpResponse(TransportError):
986
922
        DependencyNotPresent.__init__(self, 'paramiko', error)
987
923
 
988
924
 
989
 
class PointlessMerge(BzrNewError):
990
 
    """Nothing to merge."""
991
 
 
992
 
 
993
925
class UninitializableFormat(BzrNewError):
994
926
    """Format %(format)s cannot be initialised by this version of bzr."""
995
927
 
998
930
        self.format = format
999
931
 
1000
932
 
1001
 
class BadConversionTarget(BzrNewError):
1002
 
    """Cannot convert to format %(format)s.  %(problem)s"""
1003
 
 
1004
 
    def __init__(self, problem, format):
1005
 
        BzrNewError.__init__(self)
1006
 
        self.problem = problem
1007
 
        self.format = format
1008
 
 
1009
 
 
1010
933
class NoDiff(BzrNewError):
1011
934
    """Diff is not installed on this machine: %(msg)s"""
1012
935
 
1013
936
    def __init__(self, msg):
1014
 
        BzrNewError.__init__(self, msg=msg)
 
937
        super(NoDiff, self).__init__(msg=msg)
1015
938
 
1016
939
 
1017
940
class NoDiff3(BzrNewError):
1122
1045
    """Not a bzr revision-bundle: %(text)r"""
1123
1046
 
1124
1047
    def __init__(self, text):
1125
 
        BzrNewError.__init__(self)
1126
 
        self.text = text
1127
 
 
1128
 
 
1129
 
class BadBundle(BzrNewError): 
1130
 
    """Bad bzr revision-bundle: %(text)r"""
1131
 
 
1132
 
    def __init__(self, text):
1133
 
        BzrNewError.__init__(self)
1134
 
        self.text = text
1135
 
 
1136
 
 
1137
 
class MalformedHeader(BadBundle): 
1138
 
    """Malformed bzr revision-bundle header: %(text)r"""
1139
 
 
1140
 
    def __init__(self, text):
1141
 
        BzrNewError.__init__(self)
1142
 
        self.text = text
1143
 
 
1144
 
 
1145
 
class MalformedPatches(BadBundle): 
1146
 
    """Malformed patches in bzr revision-bundle: %(text)r"""
1147
 
 
1148
 
    def __init__(self, text):
1149
 
        BzrNewError.__init__(self)
1150
 
        self.text = text
1151
 
 
1152
 
 
1153
 
class MalformedFooter(BadBundle): 
1154
 
    """Malformed footer in bzr revision-bundle: %(text)r"""
1155
 
 
1156
 
    def __init__(self, text):
1157
 
        BzrNewError.__init__(self)
1158
 
        self.text = text
1159
 
 
1160
 
 
1161
 
class UnsupportedEOLMarker(BadBundle):
1162
 
    """End of line marker was not \\n in bzr revision-bundle"""    
1163
 
 
1164
 
    def __init__(self):
1165
 
        BzrNewError.__init__(self)
1166
 
 
1167
 
 
1168
 
class BadInventoryFormat(BzrNewError):
1169
 
    """Root class for inventory serialization errors"""
1170
 
 
1171
 
 
1172
 
class UnexpectedInventoryFormat(BadInventoryFormat):
1173
 
    """The inventory was not in the expected format:\n %(msg)s"""
1174
 
 
1175
 
    def __init__(self, msg):
1176
 
        BadInventoryFormat.__init__(self, msg=msg)
1177
 
 
1178
 
 
1179
 
class NoSmartServer(NotBranchError):
1180
 
    """No smart server available at %(url)s"""
1181
 
 
1182
 
    def __init__(self, url):
1183
 
        self.url = url
1184
 
 
1185
 
 
1186
 
class UnknownSSH(BzrNewError):
1187
 
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
1188
 
 
1189
 
    def __init__(self, vendor):
1190
 
        BzrNewError.__init__(self)
1191
 
        self.vendor = vendor
1192
 
 
1193
 
 
1194
 
class GhostRevisionUnusableHere(BzrNewError):
1195
 
    """Ghost revision {%(revision_id)s} cannot be used here."""
1196
 
 
1197
 
    def __init__(self, revision_id):
1198
 
        BzrNewError.__init__(self)
1199
 
        self.revision_id = revision_id
1200
 
 
1201
 
 
1202
 
class IllegalUseOfScopeReplacer(BzrNewError):
1203
 
    """ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
1204
 
 
1205
 
    is_user_error = False
1206
 
 
1207
 
    def __init__(self, name, msg, extra=None):
1208
 
        BzrNewError.__init__(self)
1209
 
        self.name = name
1210
 
        self.msg = msg
1211
 
        if extra:
1212
 
            self.extra = ': ' + str(extra)
1213
 
        else:
1214
 
            self.extra = ''
1215
 
 
1216
 
 
1217
 
class InvalidImportLine(BzrNewError):
1218
 
    """Not a valid import statement: %(msg)\n%(text)s"""
1219
 
 
1220
 
    is_user_error = False
1221
 
 
1222
 
    def __init__(self, text, msg):
1223
 
        BzrNewError.__init__(self)
1224
 
        self.text = text
1225
 
        self.msg = msg
1226
 
 
1227
 
 
1228
 
class ImportNameCollision(BzrNewError):
1229
 
    """Tried to import an object to the same name as an existing object. %(name)s"""
1230
 
 
1231
 
    is_user_error = False
1232
 
 
1233
 
    def __init__(self, name):
1234
 
        BzrNewError.__init__(self)
1235
 
        self.name = name
 
1048
        self.text = text
 
1049
 
 
1050
 
 
1051
class BadBundle(Exception): pass
 
1052
 
 
1053
 
 
1054
class MalformedHeader(BadBundle): pass
 
1055
 
 
1056
 
 
1057
class MalformedPatches(BadBundle): pass
 
1058
 
 
1059
 
 
1060
class MalformedFooter(BadBundle): pass