Skip to content

Commit

Permalink
refactor error handler: (#4354)
Browse files Browse the repository at this point in the history
Co-authored-by: maxcapodi78 <Shark78>
Co-authored-by: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com>
  • Loading branch information
maxcapodi78 and Samuelopez-ansys committed Mar 12, 2024
1 parent e6b88c8 commit 1dcf443
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions pyaedt/generic/general_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,39 @@ def _exception(ex_info, func, args, kwargs, message="Type Error"):
-------
"""

header = "**************************************************************"
_write_mes(header)
tb_data = ex_info[2]
tb_trace = traceback.format_tb(tb_data)
_write_mes("{} on {}".format(message.upper(), func.__name__))
try:
_write_mes(ex_info[1].args[0])
except (IndexError, AttributeError):
pass

for trace in traceback.format_stack():
if func.__name__ in trace:
for el in trace.split("\n"):
_write_mes(el)
exceptions = [
"_exception",
"pydev",
"traceback",
"user_function",
"__Invoke",
"interactiveshell",
"async_helpers",
]
if any(exc in trace for exc in exceptions):
continue
# if func.__name__ in trace:
for el in trace.split("\n"):
_write_mes(el)
for trace in tb_trace:
if "user_function" in trace or "async_helpers" in trace:
continue
tblist = trace.split("\n")
for el in tblist:
if func.__name__ in el:
_write_mes(el)
# if func.__name__ in el:
_write_mes(el)

_write_mes("{} on {}".format(message, func.__name__))
# try:
# _write_mes(ex_info[1].args[0])
# except (IndexError, AttributeError):
# pass

message_to_print = ""
messages = ""
Expand Down Expand Up @@ -144,6 +160,7 @@ def _exception(ex_info, func, args, kwargs, message="Type Error"):
"+".join(args)
)
)
_write_mes(header)


def normalize_path(path_in, sep=None):
Expand Down Expand Up @@ -190,30 +207,6 @@ def wrapper(*args, **kwargs):
if settings.enable_debug_logger or settings.enable_debug_edb_logger:
_log_method(user_function, args, kwargs)
return out
except TypeError:
_exception(sys.exc_info(), user_function, args, kwargs, "Type Error")
return False
except ValueError:
_exception(sys.exc_info(), user_function, args, kwargs, "Value Error")
return False
except AttributeError:
_exception(sys.exc_info(), user_function, args, kwargs, "Attribute Error")
return False
except KeyError:
_exception(sys.exc_info(), user_function, args, kwargs, "Key Error")
return False
except IndexError:
_exception(sys.exc_info(), user_function, args, kwargs, "Index Error")
return False
except AssertionError:
_exception(sys.exc_info(), user_function, args, kwargs, "Assertion Error")
return False
except NameError:
_exception(sys.exc_info(), user_function, args, kwargs, "Name Error")
return False
except IOError:
_exception(sys.exc_info(), user_function, args, kwargs, "IO Error")
return False
except MethodNotSupportedError:
message = "This Method is not supported in current AEDT Design Type."
if settings.enable_screen_logs:
Expand All @@ -228,7 +221,7 @@ def wrapper(*args, **kwargs):
_exception(sys.exc_info(), user_function, args, kwargs, "AEDT grpc API call Error")
return False
except BaseException:
_exception(sys.exc_info(), user_function, args, kwargs, "General or AEDT Error")
_exception(sys.exc_info(), user_function, args, kwargs, str(sys.exc_info()[1]).capitalize())
return False

return wrapper
Expand Down

0 comments on commit 1dcf443

Please sign in to comment.