Skip to content

Commit

Permalink
Do not print C errors by default (#926)
Browse files Browse the repository at this point in the history
* Do not print C errors by default.

Also, avoid calling _dlite.errcheck() as the first thing in
Instance.__init__() if SWIG doesn't generate a __new__() method.

* Update doc/user_guide/environment_variables.md

---------

Co-authored-by: Francesca L. Bleken <[email protected]>
  • Loading branch information
jesper-friis and francescalb authored Aug 15, 2024
1 parent e5709b0 commit ae1cd1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions bindings/python/dlite-entity-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,12 @@ def get_instance(
# Override default generated __init__() method
def __init__(self, *args, **kwargs):
# The swig-generated __new__() method is not a standard wrapper
# function and therefore bypass the standard error checking.
# Check manually that we are not in an error state.
_dlite.errcheck()
# Some versions of SWIG may generate a __new__() method that
# is not a standard wrapper function and will therefore bypass
# the standard error checking. Check manually that we are not
# in an error state.
if hasattr(self, "__new__"):
_dlite.errcheck()
if self is None:
raise _dlite.DLitePythonError(f"cannot create dlite.Instance")
Expand Down
10 changes: 7 additions & 3 deletions doc/user_guide/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ DLite-specific environment variables
plugin search paths, while it only affects the plugin search paths on
Linux.

- **DLITE_PYDEBUG**: Traceback from errors happening Python plugins are normally
lost. But, if `DLITE_PYDEBUG` is defined, a Python error message will be
written to standard error.
- **DLITE_PYDEBUG**: If defined, it will turn on printing error
messages from C to standard error.

It will also enable traceback from exceptions occuring in Python
plugins. Traceback from exceptions occurring in Python plugins
are normally lost. With `DLITE_PYDEBUG` defined the full error
message, including traceback, will be written to standard error.

- **DLITE_ATEXIT_FREE**: Free memory at exit. This might be useful to avoid
getting false positive when tracking down memory leaks with tools like valgrind.
Expand Down
2 changes: 1 addition & 1 deletion src/dlite-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ void dlite_globals_set(DLiteGlobals *globals_handler)
/* Error handler for DLite. */
static void dlite_err_handler(const ErrRecord *record)
{
if (!dlite_err_ignored_get(record->eval))
if (!dlite_err_ignored_get(record->eval) && getenv("DLITE_PYDEBUG"))
err_default_handler(record);
}

Expand Down

0 comments on commit ae1cd1a

Please sign in to comment.