1 # Copyright (C) 2008 Canonical Ltd
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """Exception classes for fastimport"""
18 # Prefix to messages to show location information
19 _LOCATION_FMT = "line %(lineno)d: "
21 # ImportError is heavily based on BzrError
23 class ImportError(Exception):
24 """The base exception class for all import processing exceptions."""
27 super(ImportError, self).__init__(self._fmt % self.__dict__)
30 class ParsingError(ImportError):
31 """The base exception class for all import processing exceptions."""
33 _fmt = _LOCATION_FMT + "Unknown Import Parsing Error"
35 def __init__(self, lineno):
37 ImportError.__init__(self)
40 class MissingBytes(ParsingError):
41 """Raised when EOF encountered while expecting to find more bytes."""
43 _fmt = (_LOCATION_FMT + "Unexpected EOF - expected %(expected)d bytes,"
46 def __init__(self, lineno, expected, found):
47 self.expected = expected
49 ParsingError.__init__(self, lineno)
52 class MissingTerminator(ParsingError):
53 """Raised when EOF encountered while expecting to find a terminator."""
55 _fmt = (_LOCATION_FMT +
56 "Unexpected EOF - expected '%(terminator)s' terminator")
58 def __init__(self, lineno, terminator):
59 self.terminator = terminator
60 ParsingError.__init__(self, lineno)
63 class InvalidCommand(ParsingError):
64 """Raised when an unknown command found."""
66 _fmt = (_LOCATION_FMT + "Invalid command '%(cmd)s'")
68 def __init__(self, lineno, cmd):
70 ParsingError.__init__(self, lineno)
73 class MissingSection(ParsingError):
74 """Raised when a section is required in a command but not present."""
76 _fmt = (_LOCATION_FMT + "Command %(cmd)s is missing section %(section)s")
78 def __init__(self, lineno, cmd, section):
80 self.section = section
81 ParsingError.__init__(self, lineno)
84 class BadFormat(ParsingError):
85 """Raised when a section is formatted incorrectly."""
87 _fmt = (_LOCATION_FMT + "Bad format for section %(section)s in "
88 "command %(cmd)s: found '%(text)s'")
90 def __init__(self, lineno, cmd, section, text):
92 self.section = section
94 ParsingError.__init__(self, lineno)
97 class InvalidTimezone(ParsingError):
98 """Raised when converting a string timezone to a seconds offset."""
100 _fmt = (_LOCATION_FMT +
101 "Timezone %(timezone)r could not be converted.%(reason)s")
103 def __init__(self, lineno, timezone, reason=None):
104 self.timezone = timezone
106 self.reason = ' ' + reason
109 ParsingError.__init__(self, lineno)
112 class PrematureEndOfStream(ParsingError):
113 """Raised when the 'done' feature was specified but missing."""
115 _fmt = (_LOCATION_FMT + "Stream end before 'done' command")
117 def __init__(self, lineno):
118 ParsingError.__init__(self, lineno)
121 class UnknownDateFormat(ImportError):
122 """Raised when an unknown date format is given."""
124 _fmt = ("Unknown date format '%(format)s'")
126 def __init__(self, format):
128 ImportError.__init__(self)
131 class MissingHandler(ImportError):
132 """Raised when a processor can't handle a command."""
134 _fmt = ("Missing handler for command %(cmd)s")
136 def __init__(self, cmd):
138 ImportError.__init__(self)
141 class UnknownParameter(ImportError):
142 """Raised when an unknown parameter is passed to a processor."""
144 _fmt = ("Unknown parameter - '%(param)s' not in %(knowns)s")
146 def __init__(self, param, knowns):
149 ImportError.__init__(self)
152 class BadRepositorySize(ImportError):
153 """Raised when the repository has an incorrect number of revisions."""
155 _fmt = ("Bad repository size - %(found)d revisions found, "
156 "%(expected)d expected")
158 def __init__(self, expected, found):
159 self.expected = expected
161 ImportError.__init__(self)
164 class BadRestart(ImportError):
165 """Raised when the import stream and id-map do not match up."""
167 _fmt = ("Bad restart - attempted to skip commit %(commit_id)s "
168 "but matching revision-id is unknown")
170 def __init__(self, commit_id):
171 self.commit_id = commit_id
172 ImportError.__init__(self)
175 class UnknownFeature(ImportError):
176 """Raised when an unknown feature is given in the input stream."""
178 _fmt = ("Unknown feature '%(feature)s' - try a later importer or "
179 "an earlier data format")
181 def __init__(self, feature):
182 self.feature = feature
183 ImportError.__init__(self)