2
0

error.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. """Base class for all exceptions from the QAPI package."""
  15. class QAPISourceError(QAPIError):
  16. """Error class for all exceptions identifying a source location."""
  17. def __init__(self, info, msg, col=None):
  18. super().__init__()
  19. self.info = info
  20. self.msg = msg
  21. self.col = col
  22. def __str__(self):
  23. loc = str(self.info)
  24. if self.col is not None:
  25. assert self.info.line is not None
  26. loc += ':%s' % self.col
  27. return loc + ': ' + self.msg
  28. class QAPIParseError(QAPISourceError):
  29. """Error class for all QAPI schema parsing errors."""
  30. def __init__(self, parser, msg):
  31. col = 1
  32. for ch in parser.src[parser.line_pos:parser.pos]:
  33. if ch == '\t':
  34. col = (col + 7) % 8 + 1
  35. else:
  36. col += 1
  37. super().__init__(parser.info, msg, col)
  38. class QAPISemError(QAPISourceError):
  39. """Error class for semantic QAPI errors."""