1# -*- coding: utf-8 -*- 2# 3# QAPI error classes 4# 5# Copyright (c) 2017-2019 Red Hat Inc. 6# 7# Authors: 8# Markus Armbruster <armbru@redhat.com> 9# Marc-André Lureau <marcandre.lureau@redhat.com> 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 15class QAPIError(Exception): 16 """Base class for all exceptions from the QAPI package.""" 17 18 19class QAPISourceError(QAPIError): 20 """Error class for all exceptions identifying a source location.""" 21 def __init__(self, info, msg, col=None): 22 super().__init__() 23 self.info = info 24 self.msg = msg 25 self.col = col 26 27 def __str__(self): 28 loc = str(self.info) 29 if self.col is not None: 30 assert self.info.line is not None 31 loc += ':%s' % self.col 32 return loc + ': ' + self.msg 33 34 35class QAPIParseError(QAPISourceError): 36 """Error class for all QAPI schema parsing errors.""" 37 def __init__(self, parser, msg): 38 col = 1 39 for ch in parser.src[parser.line_pos:parser.pos]: 40 if ch == '\t': 41 col = (col + 7) % 8 + 1 42 else: 43 col += 1 44 super().__init__(parser.info, msg, col) 45 46 47class QAPISemError(QAPISourceError): 48 """Error class for semantic QAPI errors.""" 49