]> git.proxmox.com Git - mirror_qemu.git/blob - scripts/qapi/error.py
qapi: Generalize struct member policy checking
[mirror_qemu.git] / scripts / qapi / error.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (c) 2017-2019 Red Hat Inc.
4 #
5 # Authors:
6 # Markus Armbruster <armbru@redhat.com>
7 # Marc-André Lureau <marcandre.lureau@redhat.com>
8 #
9 # This work is licensed under the terms of the GNU GPL, version 2.
10 # See the COPYING file in the top-level directory.
11
12 """
13 QAPI error classes
14
15 Common error classes used throughout the package. Additional errors may
16 be defined in other modules. At present, `QAPIParseError` is defined in
17 parser.py.
18 """
19
20 from typing import Optional
21
22 from .source import QAPISourceInfo
23
24
25 class QAPIError(Exception):
26 """Base class for all exceptions from the QAPI package."""
27
28
29 class QAPISourceError(QAPIError):
30 """Error class for all exceptions identifying a source location."""
31 def __init__(self,
32 info: Optional[QAPISourceInfo],
33 msg: str,
34 col: Optional[int] = None):
35 super().__init__()
36 self.info = info
37 self.msg = msg
38 self.col = col
39
40 def __str__(self) -> str:
41 assert self.info is not None
42 loc = str(self.info)
43 if self.col is not None:
44 assert self.info.line is not None
45 loc += ':%s' % self.col
46 return loc + ': ' + self.msg
47
48
49 class QAPISemError(QAPISourceError):
50 """Error class for semantic QAPI errors."""