/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
1
# (C) 2005 Canonical
1 by mbp at sourcefrog
import from baz patch-364
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
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
17
"""Exceptions for bzr, and reporting of them.
18
19
Exceptions are caught at a high level to report errors to the user, and
20
might also be caught inside the program.  Therefore it needs to be
21
possible to convert them to a meaningful string, and also for them to be
22
interrogated by the program.
23
24
Exceptions are defined such that the arguments given to the constructor
25
are stored in the object as properties of the same name.  When the
26
object is printed as a string, the doc string of the class is used as
27
a format string with the property dictionary available to it.
28
29
This means that exceptions can used like this:
30
31
>>> import sys
32
>>> try:
33
...   raise NotBranchError(path='/foo/bar')
34
... except:
35
...   print sys.exc_type
36
...   print sys.exc_value
1185.31.50 by John Arbash Meinel
Renaming test_sftp.py => test_sftp_transport.py, so that 'bzr selftest transport' will run it too
37
...   if hasattr(sys.exc_value, 'path'):
38
...     print sys.exc_value.path
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
39
bzrlib.errors.NotBranchError
40
Not a branch: /foo/bar
41
/foo/bar
42
43
Therefore:
44
45
 * create a new exception class for any class of error that can be
46
   usefully distinguished.
47
48
 * the printable form of an exception is generated by the base class
49
   __str__ method
1185.33.7 by Martin Pool
Better formatting of builtin errors
50
51
Exception strings should start with a capital letter and not have a final
52
fullstop.
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
53
"""
54
55
# based on Scott James Remnant's hct error classes
56
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
57
# TODO: is there any value in providing the .args field used by standard
58
# python exceptions?   A list of values with no names seems less useful 
59
# to me.
60
1185.16.63 by Martin Pool
- more error conversion
61
# TODO: Perhaps convert the exception to a string at the moment it's 
62
# constructed to make sure it will succeed.  But that says nothing about
63
# exceptions that are never raised.
64
65
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
66
# the old one.
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
67
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
68
1 by mbp at sourcefrog
import from baz patch-364
69
class BzrError(StandardError):
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
70
    def __str__(self):
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
71
        # XXX: Should we show the exception class in 
72
        # exceptions that don't provide their own message?  
73
        # maybe it should be done at a higher level
74
        ## n = self.__class__.__name__ + ': '
75
        n = ''
1195 by Martin Pool
- better error display
76
        if len(self.args) == 1:
1449 by Robert Collins
teach check about ghosts
77
            return str(self.args[0])
1195 by Martin Pool
- better error display
78
        elif len(self.args) == 2:
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
79
            # further explanation or suggestions
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
80
            try:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
81
                return n + '\n  '.join([self.args[0]] + self.args[1])
1405 by Robert Collins
remove some of the upgrade code that was duplicated with inventory_entry, and give all inventory entries a weave
82
            except TypeError:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
83
                return n + "%r" % self
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
84
        else:
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
85
            return n + `self.args`
1193 by Martin Pool
- better string formatting of BzrErrors with explanation
86
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
87
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
88
class BzrNewError(BzrError):
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
89
    """bzr error"""
90
    # base classes should override the docstring with their human-
91
    # readable explanation
92
93
    def __init__(self, **kwds):
94
        for key, value in kwds.items():
95
            setattr(self, key, value)
96
97
    def __str__(self):
98
        try:
99
            return self.__doc__ % self.__dict__
100
        except (NameError, ValueError, KeyError), e:
101
            return 'Unprintable exception %s: %s' \
102
                % (self.__class__.__name__, str(e))
103
104
1185.16.63 by Martin Pool
- more error conversion
105
class BzrCheckError(BzrNewError):
106
    """Internal check failed: %(message)s"""
107
    def __init__(self, message):
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
108
        BzrNewError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
109
        self.message = message
110
111
112
class InvalidEntryName(BzrNewError):
113
    """Invalid entry name: %(name)s"""
114
    def __init__(self, name):
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
115
        BzrNewError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
116
        self.name = name
117
118
119
class InvalidRevisionNumber(BzrNewError):
120
    """Invalid revision number %(revno)d"""
121
    def __init__(self, revno):
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
122
        BzrNewError.__init__(self)
1185.16.63 by Martin Pool
- more error conversion
123
        self.revno = revno
124
125
126
class InvalidRevisionId(BzrNewError):
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
127
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
128
    def __init__(self, revision_id, branch):
129
        BzrNewError.__init__(self)
1185.12.90 by Aaron Bentley
Fixed InvalidRevisionID handling in Branch.get_revision_xml
130
        self.revision_id = revision_id
1185.16.103 by mbp at sourcefrog
Fix up all calls to InvalidRevisionId() to specify parameters.
131
        self.branch = branch
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
132
133
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
134
class NoWorkingTree(BzrNewError):
135
    """No WorkingTree exists for %s(base)."""
136
    
137
    def __init__(self, base):
138
        BzrNewError.__init__(self)
139
        self.base = base
1506 by Robert Collins
Merge Johns current integration work.
140
141
329 by Martin Pool
- refactor command functions into command classes
142
class BzrCommandError(BzrError):
143
    # Error from malformed user command
1495 by Robert Collins
Add a --create-prefix to the new push command.
144
    # This is being misused as a generic exception
145
    # pleae subclass. RBC 20051030
1393.1.64 by Martin Pool
- improved display of some errors, including NotBranchError
146
    def __str__(self):
147
        return self.args[0]
1 by mbp at sourcefrog
import from baz patch-364
148
1495 by Robert Collins
Add a --create-prefix to the new push command.
149
150
class BzrOptionError(BzrCommandError):
151
    """Some missing or otherwise incorrect option was supplied."""
152
153
    
1185.16.65 by mbp at sourcefrog
- new commit --strict option
154
class StrictCommitFailed(Exception):
155
    """Commit refused because there are unknowns in the tree."""
1 by mbp at sourcefrog
import from baz patch-364
156
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
157
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
158
class PathError(BzrNewError):
159
    """Generic path error: %(path)r%(extra)s)"""
160
    def __init__(self, path, extra=None):
161
        BzrNewError.__init__(self)
162
        self.path = path
163
        if extra:
164
            self.extra = ': ' + str(extra)
165
        else:
166
            self.extra = ''
167
168
169
class NoSuchFile(PathError):
170
    """No such file: %(path)r%(extra)s"""
171
172
173
class FileExists(PathError):
174
    """File exists: %(path)r%(extra)s"""
175
176
177
class PermissionDenied(PathError):
178
    """Permission denied: %(path)r%(extra)s"""
179
180
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
181
class PathNotChild(BzrNewError):
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
182
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
183
    def __init__(self, path, base, extra=None):
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
184
        BzrNewError.__init__(self)
185
        self.path = path
186
        self.base = base
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
187
        if extra:
188
            self.extra = ': ' + str(extra)
189
        else:
190
            self.extra = ''
1185.31.41 by John Arbash Meinel
Creating a PathNotChild exception, and using relpath in HTTPTestUtil
191
192
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
193
class NotBranchError(BzrNewError):
194
    """Not a branch: %(path)s"""
1185.16.61 by mbp at sourcefrog
- start introducing hct error classes
195
    def __init__(self, path):
1185.16.62 by mbp at sourcefrog
- convert NotBranchError to new exception base
196
        BzrNewError.__init__(self)
197
        self.path = path
198
573 by Martin Pool
- new exception NotBranchError
199
1185.35.32 by Aaron Bentley
Fixed handling of files in mixed branches
200
class FileInWrongBranch(BzrNewError):
201
    """File %(path)s in not in branch %(branch_base)s."""
202
    def __init__(self, branch, path):
203
        BzrNewError.__init__(self)
204
        self.branch = branch
205
        self.branch_base = branch.base
206
        self.path = path
207
208
1185.1.53 by Robert Collins
raise a specific error on unsupported branches so that they can be distinguished from generic errors
209
class UnsupportedFormatError(BzrError):
210
    """Specified path is a bzr branch that we cannot read."""
211
    def __str__(self):
212
        return 'unsupported branch format: %s' % self.args[0]
213
214
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
215
class NotVersionedError(BzrNewError):
216
    """%(path)s is not versioned"""
217
    def __init__(self, path):
218
        BzrNewError.__init__(self)
219
        self.path = path
753 by Martin Pool
- new exception NotVersionedError
220
221
599 by Martin Pool
- better error reporting from smart_add
222
class BadFileKindError(BzrError):
223
    """Specified file is of a kind that cannot be added.
224
225
    (For example a symlink or device file.)"""
226
227
228
class ForbiddenFileError(BzrError):
229
    """Cannot operate on a file because it is a control file."""
230
231
614 by Martin Pool
- unify two defintions of LockError
232
class LockError(Exception):
1185.16.63 by Martin Pool
- more error conversion
233
    """Lock error"""
234
    # All exceptions from the lock/unlock functions should be from
235
    # this exception class.  They will be translated as necessary. The
236
    # original exception is available as e.original_error
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
237
238
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
239
class CommitNotPossible(LockError):
240
    """A commit was attempted but we do not have a write lock open."""
241
242
243
class AlreadyCommitted(LockError):
244
    """A rollback was requested, but is not able to be accomplished."""
245
246
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
247
class ReadOnlyError(LockError):
248
    """A write attempt was made in a read only transaction."""
249
250
1185.16.63 by Martin Pool
- more error conversion
251
class PointlessCommit(BzrNewError):
1185.16.64 by Martin Pool
- more error conversions
252
    """No changes to commit"""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
253
1185.22.1 by Michael Ellerman
Implement strict commits with --strict flag.
254
class StrictCommitFailed(Exception):
255
    """Commit refused because there are unknowns in the tree."""
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
256
257
class NoSuchRevision(BzrError):
258
    def __init__(self, branch, revision):
259
        self.branch = branch
260
        self.revision = revision
261
        msg = "Branch %s has no revision %s" % (branch, revision)
262
        BzrError.__init__(self, msg)
263
1034 by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron
264
1192 by Martin Pool
- clean up code for retrieving stored inventories
265
class HistoryMissing(BzrError):
266
    def __init__(self, branch, object_type, object_id):
267
        self.branch = branch
268
        BzrError.__init__(self,
269
                          '%s is missing %s {%s}'
270
                          % (branch, object_type, object_id))
271
272
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
273
class DivergedBranches(BzrError):
274
    def __init__(self, branch1, branch2):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
275
        BzrError.__init__(self, "These branches have diverged.")
1185.2.1 by Lalo Martins
moving DivergedBranches from bzrlib.branch to bzrlib.errors, obeying:
276
        self.branch1 = branch1
277
        self.branch2 = branch2
278
1390 by Robert Collins
pair programming worx... merge integration and weave
279
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
280
class UnrelatedBranches(BzrCommandError):
281
    def __init__(self):
282
        msg = "Branches have no common ancestor, and no base revision"\
283
            " specified."
284
        BzrCommandError.__init__(self, msg)
285
974.1.80 by Aaron Bentley
Improved merge error handling and testing
286
class NoCommonAncestor(BzrError):
287
    def __init__(self, revision_a, revision_b):
288
        msg = "Revisions have no common ancestor: %s %s." \
289
            % (revision_a, revision_b) 
290
        BzrError.__init__(self, msg)
291
292
class NoCommonRoot(BzrError):
293
    def __init__(self, revision_a, revision_b):
294
        msg = "Revisions are not derived from the same root: %s %s." \
295
            % (revision_a, revision_b) 
296
        BzrError.__init__(self, msg)
1105 by Martin Pool
- expose 'find-merge-base' as a new expert command,
297
974.2.7 by aaron.bentley at utoronto
Merged from bzr.24
298
class NotAncestor(BzrError):
299
    def __init__(self, rev_id, not_ancestor_id):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
300
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
301
                                                        rev_id)
302
        BzrError.__init__(self, msg)
303
        self.rev_id = rev_id
304
        self.not_ancestor_id = not_ancestor_id
1185.1.12 by Robert Collins
merge in lsdiff/filterdiff friendliness
305
306
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
307
class InstallFailed(BzrError):
308
    def __init__(self, revisions):
1185.1.14 by Robert Collins
remove more duplicate merged hunks. Bad MERGE3, BAD.
309
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
310
        BzrError.__init__(self, msg)
974.1.30 by aaron.bentley at utoronto
Changed copy_multi to permit failure and return a tuple, tested missing required revisions
311
        self.revisions = revisions
1154 by Martin Pool
- fix imports for moved errors
312
313
314
class AmbiguousBase(BzrError):
315
    def __init__(self, bases):
316
        msg = "The correct base is unclear, becase %s are all equally close" %\
317
            ", ".join(bases)
318
        BzrError.__init__(self, msg)
319
        self.bases = bases
320
974.1.80 by Aaron Bentley
Improved merge error handling and testing
321
class NoCommits(BzrError):
322
    def __init__(self, branch):
323
        msg = "Branch %s has no commits." % branch
324
        BzrError.__init__(self, msg)
1185.10.1 by Aaron Bentley
Added --basis option to bzr branch
325
326
class UnlistableStore(BzrError):
327
    def __init__(self, store):
328
        BzrError.__init__(self, "Store %s is not listable" % store)
329
330
class UnlistableBranch(BzrError):
331
    def __init__(self, br):
332
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
1392 by Robert Collins
reinstate testfetch test case
333
334
1185.16.116 by mbp at sourcefrog
Move weave errors into bzrlib.errors and make consistent with new system.
335
class WeaveError(BzrNewError):
336
    """Error in processing weave: %(message)s"""
337
    def __init__(self, message=None):
338
        BzrNewError.__init__(self)
339
        self.message = message
340
341
342
class WeaveRevisionAlreadyPresent(WeaveError):
343
    """Revision {%(revision_id)s} already present in %(weave)s"""
344
    def __init__(self, revision_id, weave):
345
        WeaveError.__init__(self)
346
        self.revision_id = revision_id
347
        self.weave = weave
348
349
350
class WeaveRevisionNotPresent(WeaveError):
351
    """Revision {%(revision_id)s} not present in %(weave)s"""
352
    def __init__(self, revision_id, weave):
353
        WeaveError.__init__(self)
354
        self.revision_id = revision_id
355
        self.weave = weave
356
357
358
class WeaveFormatError(WeaveError):
359
    """Weave invariant violated: %(what)s"""
360
    def __init__(self, what):
361
        WeaveError.__init__(self)
362
        self.what = what
363
364
365
class WeaveParentMismatch(WeaveError):
366
    """Parents are mismatched between two revisions."""
367
    
1393.2.1 by John Arbash Meinel
Merged in split-storage-2 branch. Need to cleanup a little bit more still.
368
1185.31.12 by John Arbash Meinel
Refactored the export code to make it easier to add new export formats.
369
class NoSuchExportFormat(BzrNewError):
370
    """Export format %(format)r not supported"""
371
    def __init__(self, format):
372
        BzrNewError.__init__(self)
373
        self.format = format
374
375
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
376
class TransportError(BzrError):
377
    """All errors thrown by Transport implementations should derive
378
    from this class.
379
    """
380
    def __init__(self, msg=None, orig_error=None):
381
        if msg is None and orig_error is not None:
382
            msg = str(orig_error)
383
        BzrError.__init__(self, msg)
384
        self.msg = msg
385
        self.orig_error = orig_error
386
387
# A set of semi-meaningful errors which can be thrown
388
class TransportNotPossible(TransportError):
389
    """This is for transports where a specific function is explicitly not
390
    possible. Such as pushing files to an HTTP server.
391
    """
392
    pass
393
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
394
395
class ConnectionError(TransportError):
396
    """A connection problem prevents file retrieval.
1185.35.31 by Aaron Bentley
Throw ConnectionError instead of NoSuchFile except when we get a 404
397
    This does not indicate whether the file exists or not; it indicates that a
398
    precondition for requesting the file was not met.
399
    """
1185.31.44 by John Arbash Meinel
Cleaned up Exceptions for all transports.
400
    def __init__(self, msg=None, orig_error=None):
401
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
402
1185.11.9 by John Arbash Meinel
Most tests pass, some problems with unavailable socket recv
403
404
class ConnectionReset(TransportError):
405
    """The connection has been closed."""
406
    pass
407
1185.14.10 by Aaron Bentley
Commit aborts with conflicts in the tree.
408
class ConflictsInTree(BzrError):
409
    def __init__(self):
410
        BzrError.__init__(self, "Working tree has conflicts.")
1185.12.49 by Aaron Bentley
Switched to ConfigObj
411
412
class ParseConfigError(BzrError):
413
    def __init__(self, errors, filename):
414
        if filename is None:
415
            filename = ""
416
        message = "Error(s) parsing config file %s:\n%s" % \
417
            (filename, ('\n'.join(e.message for e in errors)))
418
        BzrError.__init__(self, message)
1185.12.52 by Aaron Bentley
Merged more config stuff from Robert
419
1442.1.58 by Robert Collins
gpg signing of content
420
class SigningFailed(BzrError):
421
    def __init__(self, command_line):
422
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
423
                               % command_line)
1185.12.83 by Aaron Bentley
Preliminary weave merge support
424
425
class WorkingTreeNotRevision(BzrError):
426
    def __init__(self, tree):
427
        BzrError.__init__(self, "The working tree for %s has changed since"
428
                          " last commit, but weave merge requires that it be"
429
                          " unchanged." % tree.basedir)
1185.12.104 by Aaron Bentley
Merged Martin's latest
430
1185.24.1 by Aaron Bentley
Got reprocessing working
431
class CantReprocessAndShowBase(BzrNewError):
432
    """Can't reprocess and show base.
433
Reprocessing obscures relationship of conflicting lines to base."""
1185.24.2 by Aaron Bentley
Merge from mainline
434
1185.16.114 by mbp at sourcefrog
Improved topological sort
435
class GraphCycleError(BzrNewError):
436
    """Cycle in graph %(graph)r"""
437
    def __init__(self, graph):
438
        BzrNewError.__init__(self)
439
        self.graph = graph
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
440
441
class NotConflicted(BzrNewError):
1185.35.4 by Aaron Bentley
Implemented remerge
442
    """File %(filename)s is not conflicted."""
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
443
    def __init__(self, filename):
444
        BzrNewError.__init__(self)
445
        self.filename = filename
1185.35.13 by Aaron Bentley
Merged Martin
446
1492 by Robert Collins
Support decoration of commands.
447
class MustUseDecorated(Exception):
448
    """A decorating function has requested its original command be used.
449
    
450
    This should never escape bzr, so does not need to be printable.
451
    """
452
1185.35.42 by Aaron Bentley
Fixed fetch to be safer wrt ghosts and corrupt branches
453
class MissingText(BzrNewError):
454
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
455
    def __init__(self, branch, text_revision, file_id):
456
        self.branch = branch
457
        self.base = branch.base
458
        self.text_revision = text_revision
459
        self.file_id = file_id