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)