1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
__docformat__ = "restructuredtext"
19
__doc__ = "Exception classes"
22
def exception_str(exception):
24
if len(str(exception)) > 0:
25
answer +="%s" % str(exception)
26
elif hasattr(exception, "__class__"):
27
answer += exception.__class__.__name__+"\n"
29
answer = "Unknown exception"
33
class CommandFailed(Exception):
34
"""Abstract base class. Raise when a subcommand fails."""
38
class CommandFailedWrapper(CommandFailed):
40
Raise to cite another exception as a cause of command failure
42
def __init__(self, e):
44
Initialize with the wrapped type.
46
:param e: The exception that caused the command to fail
51
return exception_str(self.e)
54
class NoVersionLogs(CommandFailed):
55
"""Raise when commit fails because the tree has no logs for the version"""
56
def __init__(self, version):
58
Initialize with the version that has no logs in the tree.
60
:param version: The version that has no logs in the tree
61
:type version: `arch.Version`
66
return "No logs in tree for version \""+str(self.version)+"\"."
69
class OutOfDate(CommandFailed):
70
"""Raise when commit fails because the tree is not up to date"""
72
return "Tree is not up-to-date"
75
class EmptyCommit(CommandFailed):
76
"""Raise when commit fails because the tree contains no changes."""
78
return "Aborting empty commit."
81
class NoLogMessage(CommandFailed):
82
"""Raise when commit fails because there is no log message."""
84
return "No log message available."
87
class NoLogSummary(CommandFailed):
88
"""Raise when commit fails because there is no log message."""
90
return "Log summary is missing or blank."
92
class CommitToMirror(CommandFailed):
93
"""Raise when commit fails because it attempts to write to a mirror."""
94
def __init__(self, archive):
98
return "Attempt to commit to mirror \""+str(self.archive)+"\"."
101
class CommitFailed(CommandFailed):
102
"""Raise when commit fails"""
104
return "Unable to commit"
107
class MissingID(CommandFailed):
109
Raise to indicate a missing ID error.
111
def __init__(self, err):
113
Initialize with base error.
115
:param err: The original error that was thrown
116
:type err: `arch.util.ExecProblem`
121
return str(self.err.proc.error).rstrip("\n")
124
class LintFailure(CommandFailed):
126
Raise to indicate that some files are 'unrecognized'.
128
def __init__(self, err):
130
Initialize with lint text.
132
:param err: The original error that was thrown
138
return str(self.err).rstrip("\n")
141
class UncommittedChanges(CommandFailed):
142
"""Raise when merge fails because the tree has uncommitted changes."""
143
def __init__(self, tree):
145
Initialize with the tree that has uncommitted changes.
147
:param tree: The tree that has uncommitted changes
148
:type tree: `arch.WorkingTree`
153
return "Project tree \"%s\" has has uncommitted changes." % self.tree
156
class DirectoryExists(CommandFailed):
157
"""Raise when get fails because the tree has no logs for the version"""
158
def __init__(self, directory):
160
Initialize with the directory that exists.
162
:param directory: The directory that exists
165
self.directory=directory
168
return "Can't create directory. \""+str(self.directory)+\
171
class NoSuchAlias(CommandFailed):
172
"""Raise when command fails because there is no such alias"""
173
def __init__(self, alias):
175
Initialize with the alias that's missing.
177
:param alias: The fictional alias
183
return "No such alias: "+self.alias
186
class MergeProblem(Exception):
187
"""An error occured during merging"""
189
message = "An error occured during merging"
190
Exception.__init__(self, message)
192
class CantDetermineArchive(Exception):
193
"""Raise when no archive can be determined"""
194
def __init__(self, spec, explanation):
196
spectext = "from \"%s\"" % spec
198
spectext = "with no archive specification"
199
message = "Unable to determine archive %s:\n%s" % \
200
(spectext, explanation)
201
Exception.__init__(self, message)
203
class CantDetermineVersion(Exception):
204
"""Raise when no version can be determined"""
205
def __init__(self, spec, explain=""):
207
Initialize with the spec and optional explanation.
209
:param spec: The version specifier that was used
211
:param explain: An explanation of why the revision specifier didn't work
212
:type explain: string
220
return "Unable to determine version from \""+str(self.spec)+"\".\n"+\
224
class CantDetermineRevision(Exception):
225
"""Raise when no revision can be determined"""
226
def __init__(self, spec, explain=""):
228
Initialize with the spec and optional explanation.
230
:param spec: The revision specifier that was used
232
:param explain: An explanation of why the revision specifier didn't work
233
:type explain: string
241
return "Unable to determine revision from \""+str(self.spec)+"\".\n"+self.explain
243
class NoLatestRevision(CantDetermineRevision):
244
"""Two trees have merges in common, but merge sequence differs"""
245
def __init__(self, mine, other):
246
message = """Neither tree is the unambiguous latest revision
248
OTHER candidate: %s""" % (mine, other)
249
Exception.__init__(self, message)
252
self.message = message
254
__str__ = Exception.__str__
257
class UnrelatedTrees(CantDetermineRevision):
258
"""Two trees have no merges in common"""
259
def __init__(self, mine, other):
260
message = "No relationship could be found between these trees"
261
Exception.__init__(self, message)
265
__str__ = Exception.__str__
268
class CantParseAlias(Exception):
269
"Raise to indicate that alias parsing failed"
270
def __init__(self, text):
273
return "Can't parse alias:\""+self.text+"\""
275
class ForbiddenAliasSyntax(Exception):
276
"Raise to indicate that alias name uses forbidden syntax"
277
def __init__(self, text):
280
return "Forbidden alias syntax:\""+self.text+"\""
283
class BadOption(Exception):
284
"""Raise if a prompting option is set to a bogus value"""
288
class NoEditorSpecified(Exception):
290
Raise when an editor is requested, but none is available.
293
return "No editor specified."
296
class GetHelp(Exception):
297
"""Indicate that help is required, not normal command execution"""
300
class TreeNotContain(Exception):
301
"""Indicates that tree does not contain a given path.
303
def __init__(self, tree, path):
308
return "The tree \"%s\" does not contain \"%s\"." % \
309
(self.tree, self.path)
312
class ArchiveLookupError(Exception):
313
"""Raise to indicate an error that prevented the lookup from completing
315
def __init__(self, exception, arch_name, resource):
316
self.exception = exception
317
self.arch_name = arch_name
318
self.resource = resource
321
return "Error encountered looking up \"%s\" at %s.\n%s" % \
322
(self.arch_name, self.resource, exception_str(self.exception))
325
class SubmitError(Exception):
326
"""Error submitting an archive to an arch registry"""
327
def __init__(self, archive, location, registry, result):
328
message = """Failed to register location.
332
Result: %s""" % (archive, location, registry, result)
333
self.archive = archive
334
self.location = location
335
self.registry = registry
337
Exception.__init__(self, message)
340
class NoSuchRevision(Exception):
341
"""Raise when a required revision does not exist."""
342
def __init__(self, revision):
343
self.revision=revision
346
return "This revision does not exist:\n"+str(self.revision)
349
class NoVersionRevisions(Exception):
350
"""The tree has no revisions for the desired version."""
351
def __init__(self, tree, version):
353
self.version = version
356
return "No logs for %s present in tree %s" % (self.version, self.tree)
359
class WrongArchName(Exception):
360
"""Attempt to register the archive with the wrong name"""
361
def __init__(self, location, right_name, wrong_name):
362
self.location = location
363
self.right_name = right_name
364
self.wrong_name = wrong_name
366
return "Attempt to register %s with location %s, but that's really %s" \
367
% (self.right_name, self.location, self.wrong_name)
369
class BlandSubject(CommandFailed):
370
"""The subject line of an email has no useful information"""
372
CommandFailed.__init__(self, "No meaningful subject line")
374
class NoArchParams(Exception):
375
"""The user's parameter directory does not exist/cannot be found"""
376
def __init__(self, dir):
378
message = "Arch parameter directory does not exist\ndir: %s" % dir
379
Exception.__init__(self, message)
382
class InvalidChangeset(Exception):
383
"""The user's parameter directory does not exist/cannot be found"""
384
def __init__(self, dir):
386
message = "Directory is not a valid changeset.\ndir: %s" % dir
387
Exception.__init__(self, message)
390
class NotLibrary(Exception):
391
"""A directory that was not library was spcified as if it was one."""
392
def __init__(self, dir):
394
message = "Specified directory is not a library.\ndir: %s" % dir
395
Exception.__init__(self, message)
398
class NoGreedy(Exception):
399
"""A greedy library was required, but not available."""
400
def __init__(self, revision):
401
self.revision = revision
402
message = "No greedy libraries found adding revision.\nrevision: %s" %\
404
Exception.__init__(self, message)
406
class TreeRootNone(pybaz.errors.TreeRootError):
407
"""None was supplied instead of a valid tree root"""
409
message = "No tree root supplied"
410
Exception.__init__(self, message)
412
class IsAutoAlias(CommandFailed):
413
"""User attempted to redefine an auto alias"""
414
def __init__(self, alias, message=None):
415
self.revision = alias
417
message = "\"%s\" is an auto alias." % alias
418
Exception.__init__(self, message)
420
class TarError(Exception):
421
"""An error occurred using tar"""
422
def __init__(self, msg):
423
Exception.__init__(self, msg)
426
class UnknownCompressionMethod(TarError):
427
"""User specified an unknown compression method"""
428
def __init__(self, method):
430
msg = "Compression method \"%s\" is unknown." % self.method
431
TarError.__init__(self, msg)
433
class NoUnambiguousParent(TarError):
434
"""This tarfile doesn't follow the convention of a single root dir"""
435
def __init__(self, file, dir):
438
msg = "The file \"%s\" does not have \"%s\" as a parent" % (self.file,
440
TarError.__init__(self, msg)
442
class UnsupportedScheme(Exception):
443
def __init__(self, location):
444
msg = "Unsupported scheme: %s" % location
445
self.location = location
446
Exception.__init__(self, msg)
448
# arch-tag: fd8812b0-2d93-4b7c-a669-24a915d86ec1