1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2017-2019 Red Hat Inc.
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.
15 Common error classes used throughout the package. Additional errors may
16 be defined in other modules. At present, `QAPIParseError` is defined in
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."""
32 info: Optional[QAPISourceInfo],
34 col: Optional[int] = None):
40 def __str__(self) -> str:
41 assert self.info is not None
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."""