Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug[next]: Improve error message on invalid call to field operator and program #1323

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/gt4py/next/ffront/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from gt4py._core import definitions as core_defs
from gt4py.eve import utils as eve_utils
from gt4py.eve.extended_typing import Any, Optional
from gt4py.next import allocators as next_allocators, embedded as next_embedded
from gt4py.next import allocators as next_allocators, embedded as next_embedded, errors
from gt4py.next.common import Dimension, DimensionKind, GridType
from gt4py.next.embedded import operators as embedded_operators
from gt4py.next.ffront import (
Expand Down Expand Up @@ -344,7 +344,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)
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/ffront/foast_passes/type_deduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,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)
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/ffront/past_passes/type_deduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest

import gt4py.next as gtx
from gt4py.next import errors

from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import IDim, Ioff, JDim, cartesian_case, fieldview_backend
Expand Down Expand Up @@ -222,7 +223,7 @@ def test_wrong_argument_type(cartesian_case, copy_program_def):
inp = cartesian_case.as_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={})
Expand Down