aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-03-07 10:16:27 -0800
committerDylan Baker <dylan@pnwbakers.com>2022-03-07 12:33:33 -0800
commite2e74ee371df0cdc940901e7ea68a35970f54033 (patch)
tree46faf9a59c034ada44fffa9783d4566d11a83444 /mesonbuild/mesonlib
parent8434fb14095febb2b2d5f708e9f324366c3b521f (diff)
downloadmeson-e2e74ee371df0cdc940901e7ea68a35970f54033.zip
meson-e2e74ee371df0cdc940901e7ea68a35970f54033.tar.gz
meson-e2e74ee371df0cdc940901e7ea68a35970f54033.tar.bz2
mesonlib: Add a from_node initializer to MesonException
This is useful when creating an exception with a node option, with less typing.
Diffstat (limited to 'mesonbuild/mesonlib')
-rw-r--r--mesonbuild/mesonlib/universal.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
index 41bd1f2..99bcd32 100644
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -41,6 +41,7 @@ if T.TYPE_CHECKING:
from ..build import ConfigurationData
from ..coredata import KeyedOptionDictType, UserOption
from ..compilers.compilers import Compiler
+ from ..mparser import BaseNode
FileOrString = T.Union['File', str]
@@ -171,6 +172,15 @@ class MesonException(Exception):
self.lineno = lineno
self.colno = colno
+ @classmethod
+ def from_node(cls, *args: object, node: BaseNode) -> MesonException:
+ """Create a MesonException with location data from a BaseNode
+
+ :param node: A BaseNode to set location data from
+ :return: A Meson Exception instance
+ """
+ return cls(*args, file=node.filename, lineno=node.lineno, colno=node.colno)
+
class MesonBugException(MesonException):
'''Exceptions thrown when there is a clear Meson bug that should be reported'''