mesonlib: Add a from_node initializer to MesonException
This is useful when creating an exception with a node option, with less
typing.
@@ -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'''
