From 093dbb9ade689aae47c841daf8981369ab575c5a Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Wed, 16 Aug 2023 11:00:01 +0200 Subject: [PATCH 1/3] Improve error message on invalid call to field operator and program --- src/gt4py/next/ffront/decorator.py | 5 ++++- src/gt4py/next/ffront/foast_passes/type_deduction.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gt4py/next/ffront/decorator.py b/src/gt4py/next/ffront/decorator.py index 5b4d32b59e..f2a7bae3e3 100644 --- a/src/gt4py/next/ffront/decorator.py +++ b/src/gt4py/next/ffront/decorator.py @@ -32,6 +32,7 @@ from gt4py._core import definitions as core_defs from gt4py.eve.extended_typing import Any, Optional from gt4py.eve.utils import UIDGenerator +from gt4py.next import errors from gt4py.next.common import Dimension, DimensionKind, GridType from gt4py.next.ffront import ( dialect_ast_enums, @@ -297,7 +298,9 @@ def _validate_args(self, *args, **kwargs) -> None: raise_exception=True, ) except ValueError as err: - raise TypeError(f"Invalid argument types in call to `{self.past_node.id}`!") from err + raise errors.DSLError( + None, f"Invalid argument types in call to `{self.past_node.id}`.\n{err}" + ) from err def _process_args(self, args: tuple, kwargs: dict) -> tuple[tuple, tuple, dict[str, Any]]: self._validate_args(*args, **kwargs) diff --git a/src/gt4py/next/ffront/foast_passes/type_deduction.py b/src/gt4py/next/ffront/foast_passes/type_deduction.py index bd7eddbcdd..64abefecbb 100644 --- a/src/gt4py/next/ffront/foast_passes/type_deduction.py +++ b/src/gt4py/next/ffront/foast_passes/type_deduction.py @@ -689,7 +689,7 @@ def visit_Call(self, node: foast.Call, **kwargs) -> foast.Call: ) except ValueError as err: raise errors.DSLError( - node.location, f"Invalid argument types in call to `{new_func}`!" + node.location, f"Invalid argument types in call to `{new_func}`.\n{err}" ) from err return_type = type_info.return_type(func_type, with_args=arg_types, with_kwargs=kwarg_types) From 39119f3c00cb15b31f8c65cf86643a0e33bf77ba Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Wed, 16 Aug 2023 11:09:15 +0200 Subject: [PATCH 2/3] Small fix --- src/gt4py/next/ffront/past_passes/type_deduction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gt4py/next/ffront/past_passes/type_deduction.py b/src/gt4py/next/ffront/past_passes/type_deduction.py index ed3bdae3ff..a75ab335fb 100644 --- a/src/gt4py/next/ffront/past_passes/type_deduction.py +++ b/src/gt4py/next/ffront/past_passes/type_deduction.py @@ -231,7 +231,7 @@ def visit_Call(self, node: past.Call, **kwargs): ) except ValueError as ex: - raise errors.DSLError(node.location, f"Invalid call to `{node.func.id}`.") from ex + raise errors.DSLError(node.location, f"Invalid call to `{node.func.id}`.\n{ex}") from ex return past.Call( func=new_func, From 32bcb6a035dd95f9b231e6815d7b7d48396c2523 Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Mon, 21 Aug 2023 09:44:20 +0200 Subject: [PATCH 3/3] Fix CI --- .../feature_tests/ffront_tests/test_program.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py index f12e10fcab..d66f8f2bf3 100644 --- a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py +++ b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_program.py @@ -20,6 +20,7 @@ import pytest import gt4py.next as gtx +from gt4py.next import errors from gt4py.next.program_processors.runners import dace_iterator from next_tests.integration_tests import cases @@ -227,7 +228,7 @@ def test_wrong_argument_type(cartesian_case, copy_program_def): inp = gtx.np_as_located_field(JDim)(np.ones((cartesian_case.default_sizes[JDim],))) out = cases.allocate(cartesian_case, copy_program, "out").strategy(cases.ConstInitializer(1))() - with pytest.raises(TypeError) as exc_info: + with pytest.raises(errors.DSLError) as exc_info: # program is defined on Field[[IDim], ...], but we call with # Field[[JDim], ...] copy_program(inp, out, offset_provider={})