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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """Exception classes for fastimport"""
19 from bzrlib
import errors
as bzr_errors
22 # Prefix to messages to show location information
23 _LOCATION_FMT
= "line %(lineno)d: "
26 class ImportError(bzr_errors
.BzrError
):
27 """The base exception class for all import processing exceptions."""
29 _fmt
= "Unknown Import Error"
32 class ParsingError(ImportError):
33 """The base exception class for all import processing exceptions."""
35 _fmt
= _LOCATION_FMT
+ "Unknown Import Parsing Error"
37 def __init__(self
, lineno
):
38 ImportError.__init
__(self
)
42 class MissingBytes(ParsingError
):
43 """Raised when EOF encountered while expecting to find more bytes."""
45 _fmt
= (_LOCATION_FMT
+ "Unexpected EOF - expected %(expected)d bytes,"
48 def __init__(self
, lineno
, expected
, found
):
49 ParsingError
.__init
__(self
, lineno
)
50 self
.expected
= expected
54 class MissingTerminator(ParsingError
):
55 """Raised when EOF encountered while expecting to find a terminator."""
57 _fmt
= (_LOCATION_FMT
+
58 "Unexpected EOF - expected '%(terminator)s' terminator")
60 def __init__(self
, lineno
, terminator
):
61 ParsingError
.__init
__(self
, lineno
)
62 self
.terminator
= terminator
65 class InvalidCommand(ParsingError
):
66 """Raised when an unknown command found."""
68 _fmt
= (_LOCATION_FMT
+ "Invalid command '%(cmd)s'")
70 def __init__(self
, lineno
, cmd
):
71 ParsingError
.__init
__(self
, lineno
)
75 class MissingSection(ParsingError
):
76 """Raised when a section is required in a command but not present."""
78 _fmt
= (_LOCATION_FMT
+ "Command %(cmd)s is missing section %(section)s")
80 def __init__(self
, lineno
, cmd
, section
):
81 ParsingError
.__init
__(self
, lineno
)
83 self
.section
= section
86 class BadFormat(ParsingError
):
87 """Raised when a section is formatted incorrectly."""
89 _fmt
= (_LOCATION_FMT
+ "Bad format for section %(section)s in "
90 "command %(cmd)s: found '%(text)s'")
92 def __init__(self
, lineno
, cmd
, section
, text
):
93 ParsingError
.__init
__(self
, lineno
)
95 self
.section
= section
99 class InvalidTimezone(ParsingError
):
100 """Raised when converting a string timezone to a seconds offset."""
102 _fmt
= (_LOCATION_FMT
+
103 "Timezone %(timezone)r could not be converted.%(reason)s")
105 def __init__(self
, lineno
, timezone
, reason
=None):
106 ParsingError
.__init
__(self
, lineno
)
107 self
.timezone
= timezone
109 self
.reason
= ' ' + reason
114 class UnknownDateFormat(ImportError):
115 """Raised when an unknown date format is given."""
117 _fmt
= ("Unknown date format '%(format)s'")
119 def __init__(self
, format
):
120 ImportError.__init
__(self
)
124 class MissingHandler(ImportError):
125 """Raised when a processor can't handle a command."""
127 _fmt
= ("Missing handler for command %(cmd)s")
129 def __init__(self
, cmd
):
130 ImportError.__init
__(self
)
134 class UnknownParameter(ImportError):
135 """Raised when an unknown parameter is passed to a processor."""
137 _fmt
= ("Unknown parameter - '%(param)s' not in %(knowns)s")
139 def __init__(self
, param
, knowns
):
140 ImportError.__init
__(self
)
145 class BadRepositorySize(ImportError):
146 """Raised when the repository has an incorrect number of revisions."""
148 _fmt
= ("Bad repository size - %(found)d revisions found, "
149 "%(expected)d expected")
151 def __init__(self
, expected
, found
):
152 ImportError.__init
__(self
)
153 self
.expected
= expected
157 class BadRestart(ImportError):
158 """Raised when the import stream and id-map do not match up."""
160 _fmt
= ("Bad restart - attempted to skip commit %(commit_id)s "
161 "but matching revision-id is unknown")
163 def __init__(self
, commit_id
):
164 ImportError.__init
__(self
)
165 self
.commit_id
= commit_id
168 class UnknownFeature(ImportError):
169 """Raised when an unknown feature is given in the input stream."""
171 _fmt
= ("Unknown feature '%(feature)s' - try a later importer or "
172 "an earlier data format")
174 def __init__(self
, feature
):
175 ImportError.__init
__(self
)
176 self
.feature
= feature