xref: /llvm-project/cross-project-tests/debuginfo-tests/dexter/dex/utils/Exceptions.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
1# DExTer : Debugging Experience Tester
2# ~~~~~~   ~         ~~         ~   ~~
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7"""Provides Dexter-specific exception types."""
8
9
10class Dexception(Exception):
11    """All dexter-specific exceptions derive from this."""
12
13    pass
14
15
16class Error(Dexception):
17    """Error.  Prints 'error: <message>' without a traceback."""
18
19    pass
20
21
22class DebuggerException(Dexception):
23    """Any error from using the debugger."""
24
25    def __init__(self, msg, orig_exception=None):
26        super(DebuggerException, self).__init__(msg)
27        self.msg = msg
28        self.orig_exception = orig_exception
29
30    def __str__(self):
31        return str(self.msg)
32
33
34class LoadDebuggerException(DebuggerException):
35    """If specified debugger cannot be loaded."""
36
37    pass
38
39
40class NotYetLoadedDebuggerException(LoadDebuggerException):
41    """If specified debugger has not yet been attempted to load."""
42
43    def __init__(self):
44        super(NotYetLoadedDebuggerException, self).__init__(
45            "not loaded", orig_exception=None
46        )
47
48
49class CommandParseError(Dexception):
50    """If a command instruction cannot be successfully parsed."""
51
52    def __init__(self, *args, **kwargs):
53        super(CommandParseError, self).__init__(*args, **kwargs)
54        self.filename = None
55        self.lineno = None
56        self.info = None
57        self.src = None
58        self.caret = None
59
60
61class NonFloatValueInCommand(CommandParseError):
62    """If a command has the float_range arg but at least one of its expected
63    values cannot be converted to a float."""
64
65    def __init__(self, *args, **kwargs):
66        super(NonFloatValueInCommand, self).__init__(*args, **kwargs)
67        self.value = None
68
69
70class ToolArgumentError(Dexception):
71    """If a tool argument is invalid."""
72
73    pass
74
75
76class BuildScriptException(Dexception):
77    """If there is an error in a build script file."""
78
79    def __init__(self, *args, **kwargs):
80        self.script_error = kwargs.pop("script_error", None)
81        super(BuildScriptException, self).__init__(*args, **kwargs)
82
83
84class HeuristicException(Dexception):
85    """If there was a problem with the heuristic."""
86
87    pass
88