2
0

error.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. class QAPIError(Exception):
  14. def __init__(self, info, col, msg):
  15. Exception.__init__(self)
  16. self.info = info
  17. self.col = col
  18. self.msg = msg
  19. def __str__(self):
  20. loc = str(self.info)
  21. if self.col is not None:
  22. assert self.info.line is not None
  23. loc += ':%s' % self.col
  24. return loc + ': ' + self.msg
  25. class QAPIParseError(QAPIError):
  26. def __init__(self, parser, msg):
  27. col = 1
  28. for ch in parser.src[parser.line_pos:parser.pos]:
  29. if ch == '\t':
  30. col = (col + 7) % 8 + 1
  31. else:
  32. col += 1
  33. super().__init__(parser.info, col, msg)
  34. class QAPISemError(QAPIError):
  35. def __init__(self, info, msg):
  36. super().__init__(info, None, msg)