MAINTAINERS: Add myself as streams maintainer
[qemu/ar7.git] / scripts / qapi / error.py
blobae60d9e2fe8166f82e4601da3d70e599529b5ba0
1 # -*- coding: utf-8 -*-
3 # QAPI error classes
5 # Copyright (c) 2017-2019 Red Hat Inc.
7 # Authors:
8 # Markus Armbruster <armbru@redhat.com>
9 # Marc-André Lureau <marcandre.lureau@redhat.com>
11 # This work is licensed under the terms of the GNU GPL, version 2.
12 # See the COPYING file in the top-level directory.
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
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
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
38 super().__init__(parser.info, col, msg)
41 class QAPISemError(QAPIError):
42 def __init__(self, info, msg):
43 super().__init__(info, None, msg)