Skip to content

Commit 6f222d9

Browse files
authored
Hide traceback for epyccel and lambdify errors (pyccel#1869)
Add a `try/except` around internal Pyccel calls to catch all `PyccelError`s. This allows the shortest possible traceback to be shown to the user when the error is recognised, handled and reported by Pyccel. Fixes pyccel#1868.
1 parent 0305011 commit 6f222d9

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
2222
- #1844 : Add line numbers and code to errors from built-in function calls.
2323
- #1867 : Add a `use_out` parameter to `pyccel.lambdify` to avoid unnecessary memory allocation.
2424
- #1867 : Auto-generate a docstring for functions generated via calls to `pyccel.lambdify`.
25+
- #1868 : Hide traceback for `epyccel` and `lambdify` errors.
2526
- \[INTERNALS\] Added `container_rank` property to `ast.datatypes.PyccelType` objects.
2627
- \[DEVELOPER\] Added an improved traceback to the developer-mode errors for errors in function calls.
2728

pyccel/commands/epyccel.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from pyccel.utilities.strings import random_string
2020
from pyccel.codegen.pipeline import execute_pyccel
21-
from pyccel.errors.errors import ErrorsMode
21+
from pyccel.errors.errors import ErrorsMode, PyccelError
2222

2323
__all__ = ['get_source_function', 'epyccel_seq', 'epyccel']
2424

@@ -359,6 +359,8 @@ def epyccel( python_function_or_module, **kwargs ):
359359
fun_name = python_function_or_module.__name__ if fun else None
360360
success = True
361361
# error handling carried out after broadcast to prevent deadlocks
362+
except PyccelError as e:
363+
raise type(e)(str(e)) from None
362364
except BaseException as e: # pylint: disable=broad-except
363365
exc_info = e
364366
success = False
@@ -396,7 +398,10 @@ def epyccel( python_function_or_module, **kwargs ):
396398

397399
# Serial version
398400
else:
399-
mod, fun = epyccel_seq( python_function_or_module, **kwargs )
401+
try:
402+
mod, fun = epyccel_seq( python_function_or_module, **kwargs )
403+
except PyccelError as e:
404+
raise type(e)(str(e)) from None
400405

401406
# Return Fortran function (if any), otherwise module
402407
return fun or mod

pyccel/commands/lambdify.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import sympy as sp
66
from packaging import version
77

8-
from pyccel.commands.epyccel import epyccel
8+
from pyccel.commands.epyccel import epyccel
99
from pyccel.utilities.strings import random_string
10+
from pyccel.errors.errors import PyccelError
1011

1112
if version.parse(sp.__version__) >= version.parse('1.8'):
1213
from sympy.printing.numpy import NumPyPrinter
@@ -117,6 +118,10 @@ def lambdify(expr : sp.Expr, args : 'dict[sp.Symbol, str]', *, result_type : str
117118
docstring += '\n """'
118119

119120
func = '\n'.join((numpy_import, decorators, signature, docstring, code))
120-
package = epyccel(func, **kwargs)
121+
try:
122+
package = epyccel(func, **kwargs)
123+
except PyccelError as e:
124+
raise type(e)(str(e)) from None
125+
121126
return getattr(package, func_name)
122127

0 commit comments

Comments
 (0)