]>
Commit | Line | Data |
---|---|---|
e6c42b96 MA |
1 | # -*- coding: utf-8 -*- |
2 | # | |
3 | # QAPI error classes | |
4 | # | |
5 | # Copyright (c) 2017-2019 Red Hat Inc. | |
6 | # | |
7 | # Authors: | |
8 | # Markus Armbruster <[email protected]> | |
9 | # Marc-André Lureau <[email protected]> | |
10 | # | |
11 | # This work is licensed under the terms of the GNU GPL, version 2. | |
12 | # See the COPYING file in the top-level directory. | |
13 | ||
14 | ||
15 | class QAPIError(Exception): | |
16 | def __init__(self, info, col, msg): | |
17 | Exception.__init__(self) | |
18 | self.info = info | |
19 | self.col = col | |
20 | self.msg = msg | |
21 | ||
22 | def __str__(self): | |
23 | loc = str(self.info) | |
24 | if self.col is not None: | |
25 | assert self.info.line is not None | |
26 | loc += ':%s' % self.col | |
27 | return loc + ': ' + self.msg | |
28 | ||
29 | ||
30 | class QAPIParseError(QAPIError): | |
31 | def __init__(self, parser, msg): | |
32 | col = 1 | |
33 | for ch in parser.src[parser.line_pos:parser.pos]: | |
34 | if ch == '\t': | |
35 | col = (col + 7) % 8 + 1 | |
36 | else: | |
37 | col += 1 | |
2cae67bc | 38 | super().__init__(parser.info, col, msg) |
e6c42b96 MA |
39 | |
40 | ||
41 | class QAPISemError(QAPIError): | |
42 | def __init__(self, info, msg): | |
2cae67bc | 43 | super().__init__(info, None, msg) |