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

refactor[next] error handling #1275

Merged
merged 56 commits into from Jul 21, 2023
Merged

refactor[next] error handling #1275

merged 56 commits into from Jul 21, 2023

Conversation

petiaccja
Copy link
Contributor

@petiaccja petiaccja commented Jun 21, 2023

Contents:

  • Add CompilerError and subclasses for specific errors
    • Location info + error msg
  • Removed old GT*Error classes, DialetSyntaxError classes
  • Replaced most raise statements in frontend [needs further work]
    • Most error messages now have proper location information
    • Some of the errors have updated types and error messages
  • Replaced raise statements in type_system [needs further work]
  • Added sys.excepthook for printing uncaught CompilerErrors
  • Added __str__ method for printing uncaught errors in PyCharm

Usage:

  • Compilation errors: raise one of the classes from next.errors (alias of next.errors.exceptions) or create a new class if makes sense
  • General errors: use Python's builtin exception classes. If necessary, new classes can be added somewhere in next.errors.
  • Don't override sys.excepthook!

Results:

Errors are displayed similarly to Python syntax errors:

Source location (most recent call last):
  File "/home/petiaccja/Work/ETHZ/code/gt4py_petiaccja/tests/next_tests/exception_printing.py", line 23
    def foo(var):
            ^^^
gt4py.next.errors.exceptions.MissingParameterAnnotationError: parameter 'var' is missing type annotations

@petiaccja petiaccja changed the title Error handling refactor[next] error handling Jun 23, 2023
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main changes in the PR look good to me. I've left many comments, questions and suggestions, but usually minor things.

src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/eve/concepts.py Show resolved Hide resolved
tests/next_tests/exception_printing.py Outdated Show resolved Hide resolved
petiaccja and others added 7 commits July 12, 2023 11:25
Co-authored-by: Enrique G. Paredes <18477+egparedes@users.noreply.github.com>
Co-authored-by: Enrique G. Paredes <18477+egparedes@users.noreply.github.com>
Co-authored-by: Enrique G. Paredes <18477+egparedes@users.noreply.github.com>
Co-authored-by: Enrique G. Paredes <18477+egparedes@users.noreply.github.com>
src/gt4py/next/ffront/decorator.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/__init__.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/formatting.py Show resolved Hide resolved
src/gt4py/next/ffront/dialect_parser.py Show resolved Hide resolved
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the coding and design issues have been addressed. I only have comments about coding style. I'll approve the PR as soon as they get addressed.

src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/exceptions.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/excepthook.py Outdated Show resolved Hide resolved
src/gt4py/next/errors/formatting.py Outdated Show resolved Hide resolved
src/gt4py/next/ffront/dialect_parser.py Outdated Show resolved Hide resolved
Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILGTM.

@petiaccja petiaccja merged commit 1ebd302 into GridTools:main Jul 21, 2023
30 checks passed
@petiaccja petiaccja deleted the exceptions branch July 21, 2023 08:37
tehrengruber added a commit that referenced this pull request Jan 22, 2024
…d program (#1323)

After #1275 most of the error message given to the user when calling a field operator or program with invalid arguments was only available in verbose mode. This PR shows this information again.

```python
@field_operator
def foo(x: IField):
    return x

@field_operator
def testee(a: IField, b: IField, c: IField) -> IField:
    return foo(1)
```

```
gt4py.next.errors.exceptions.DSLError: Invalid argument types in call to `foo`.
E           Invalid call to function of type `FieldOperatorType(definition=FunctionType(pos_only_args=[], pos_or_kw_args={'x': FieldType(dims=[Dimension(value='IDim', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], dtype=ScalarType(kind=<ScalarKind.INT32: 32>, shape=None))}, kw_only_args={}, returns=FieldType(dims=[Dimension(value='IDim', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)], dtype=ScalarType(kind=<ScalarKind.INT32: 32>, shape=None))))`:
E             - Expected argument `x` to be of type `Field[[IDim], int32]`, but got `int32`.
E             File ".../gt4py_functional/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_arg_call_interface.py", line 113
E                       return foo(1)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants