/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to errors.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-17 23:37:24 UTC
  • mto: (0.64.114 trunk)
  • mto: This revision was merged to the branch mainline in revision 6631.
  • Revision ID: ian.clatworthy@canonical.com-20090217233724-y6q12cyoyln6vkh6
code & tests for file copying

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 Canonical Ltd
 
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
 
 
17
"""Exception classes for fastimport"""
 
18
 
 
19
from bzrlib import errors as bzr_errors
 
20
 
 
21
 
 
22
# Prefix to messages to show location information
 
23
_LOCATION_FMT = "line %(lineno)d: "
 
24
 
 
25
 
 
26
class ImportError(bzr_errors.BzrError):
 
27
    """The base exception class for all import processing exceptions."""
 
28
 
 
29
    _fmt = "Unknown Import Error"
 
30
 
 
31
 
 
32
class ParsingError(ImportError):
 
33
    """The base exception class for all import processing exceptions."""
 
34
 
 
35
    _fmt = _LOCATION_FMT + "Unknown Import Parsing Error"
 
36
 
 
37
    def __init__(self, lineno):
 
38
        ImportError.__init__(self)
 
39
        self.lineno = lineno
 
40
 
 
41
 
 
42
class MissingBytes(ParsingError):
 
43
    """Raised when EOF encountered while expecting to find more bytes."""
 
44
 
 
45
    _fmt = (_LOCATION_FMT + "Unexpected EOF - expected %(expected)d bytes,"
 
46
        " found %(found)d")
 
47
 
 
48
    def __init__(self, lineno, expected, found):
 
49
        ParsingError.__init__(self, lineno)
 
50
        self.expected = expected
 
51
        self.found = found
 
52
 
 
53
 
 
54
class MissingTerminator(ParsingError):
 
55
    """Raised when EOF encountered while expecting to find a terminator."""
 
56
 
 
57
    _fmt = (_LOCATION_FMT +
 
58
        "Unexpected EOF - expected '%(terminator)s' terminator")
 
59
 
 
60
    def __init__(self, lineno, terminator):
 
61
        ParsingError.__init__(self, lineno)
 
62
        self.terminator = terminator
 
63
 
 
64
 
 
65
class InvalidCommand(ParsingError):
 
66
    """Raised when an unknown command found."""
 
67
 
 
68
    _fmt = (_LOCATION_FMT + "Invalid command '%(cmd)s'")
 
69
 
 
70
    def __init__(self, lineno, cmd):
 
71
        ParsingError.__init__(self, lineno)
 
72
        self.cmd = cmd
 
73
 
 
74
 
 
75
class MissingSection(ParsingError):
 
76
    """Raised when a section is required in a command but not present."""
 
77
 
 
78
    _fmt = (_LOCATION_FMT + "Command %(cmd)s is missing section %(section)s")
 
79
 
 
80
    def __init__(self, lineno, cmd, section):
 
81
        ParsingError.__init__(self, lineno)
 
82
        self.cmd = cmd
 
83
        self.section = section
 
84
 
 
85
 
 
86
class BadFormat(ParsingError):
 
87
    """Raised when a section is formatted incorrectly."""
 
88
 
 
89
    _fmt = (_LOCATION_FMT + "Bad format for section %(section)s in "
 
90
        "command %(cmd)s: found '%(text)s'")
 
91
 
 
92
    def __init__(self, lineno, cmd, section, text):
 
93
        ParsingError.__init__(self, lineno)
 
94
        self.cmd = cmd
 
95
        self.section = section
 
96
        self.text = text
 
97
 
 
98
 
 
99
class InvalidTimezone(ParsingError):
 
100
    """Raised when converting a string timezone to a seconds offset."""
 
101
 
 
102
    _fmt = (_LOCATION_FMT +
 
103
        "Timezone %(timezone)r could not be converted.%(reason)s")
 
104
 
 
105
    def __init__(self, lineno, timezone, reason=None):
 
106
        ParsingError.__init__(self, lineno)
 
107
        self.timezone = timezone
 
108
        if reason:
 
109
            self.reason = ' ' + reason
 
110
        else:
 
111
            self.reason = ''
 
112
 
 
113
 
 
114
class UnknownDateFormat(ImportError):
 
115
    """Raised when an unknown date format is given."""
 
116
 
 
117
    _fmt = ("Unknown date format '%(format)s'")
 
118
 
 
119
    def __init__(self, format):
 
120
        ImportError.__init__(self)
 
121
        self.format = format
 
122
 
 
123
 
 
124
class MissingHandler(ImportError):
 
125
    """Raised when a processor can't handle a command."""
 
126
 
 
127
    _fmt = ("Missing handler for command %(cmd)s")
 
128
 
 
129
    def __init__(self, cmd):
 
130
        ImportError.__init__(self)
 
131
        self.cmd = cmd
 
132
 
 
133
 
 
134
class UnknownParameter(ImportError):
 
135
    """Raised when an unknown parameter is passed to a processor."""
 
136
 
 
137
    _fmt = ("Unknown parameter - '%(param)s' not in %(knowns)s")
 
138
 
 
139
    def __init__(self, param, knowns):
 
140
        ImportError.__init__(self)
 
141
        self.param = param
 
142
        self.knowns = knowns
 
143
 
 
144
 
 
145
class BadRepositorySize(ImportError):
 
146
    """Raised when the repository has an incorrect number of revisions."""
 
147
 
 
148
    _fmt = ("Bad repository size - %(found)d revisions found, "
 
149
        "%(expected)d expected")
 
150
 
 
151
    def __init__(self, expected, found):
 
152
        ImportError.__init__(self)
 
153
        self.expected = expected
 
154
        self.found = found
 
155
 
 
156
 
 
157
class BadRestart(ImportError):
 
158
    """Raised when the import stream and id-map do not match up."""
 
159
 
 
160
    _fmt = ("Bad restart - attempted to skip commit %(commit_id)s "
 
161
        "but matching revision-id is unknown")
 
162
 
 
163
    def __init__(self, commit_id):
 
164
        ImportError.__init__(self)
 
165
        self.commit_id = commit_id