hw/ide: Add the possibility to disable the CompactFlash device in the build
[qemu/ar7.git] / scripts / qapi / error.py
blobe35e4ddb26a01085d2f86f201791a9e86a2d9f6f
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2017-2019 Red Hat Inc.
5 # Authors:
6 # Markus Armbruster <armbru@redhat.com>
7 # Marc-André Lureau <marcandre.lureau@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2.
10 # See the COPYING file in the top-level directory.
12 """
13 QAPI error classes
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 """
20 from typing import Optional
22 from .source import QAPISourceInfo
25 class QAPIError(Exception):
26 """Base class for all exceptions from the QAPI package."""
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
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
49 class QAPISemError(QAPISourceError):
50 """Error class for semantic QAPI errors."""