uibcdf / MolSysMT

Open source library to work with molecular systems
https://www.uibcdf.org/MolSysMT/
Other
12 stars 3 forks source link

Exceptions reporting more information #61

Closed dprada closed 2 years ago

dprada commented 2 years ago

We would like to have exceptions returning more information. For example (see this former version of not_implemented_version_error.py):

For instance, if the user asks for a conversion not implemented, raising an exception with the following message would informative:

 message = (
                f"The conversion from {from_form} to {to_form} in \"{caller_name}\" has not been implemented yet. "
                f"Check {api_doc} for more information. "
                f"Write a new issue in {__github_issues_web__} asking for its implementation."
                )

In order to do this, as @Daniel-Ibarrola addressed in https://github.com/uibcdf/MolSysMT/pull/54#discussion_r907620748, we need to work properly with the module stack from the library inspect. Example:

def __init__(self, from_form, to_form):

        from molsysmt import __github_issues_web__
        from inspect import stack

        all_stack_frames = stack()
        caller_stack_frame = all_stack_frames[1]
        caller_name = caller_stack_frame[3]

        api_doc = ''

        message = (
                f"The conversion from {from_form} to {to_form} in \"{caller_name}\" has not been implemented yet. "
                f"Check {api_doc} for more information. "
                f"Write a new issue in {__github_issues_web__} asking for its implementation."
                )

        super().__init__(message)
dprada commented 2 years ago

In the case of raising WrongGetArgumentError, the idea was something as (see former file):

    def __init__(self, argument=None):

        from molsysmt import __github_issues_web__
        from inspect import stack

        all_stack_frames = stack()
        caller_stack_frame = all_stack_frames[1]
        caller_name = caller_stack_frame[3]

        api_doc = ''

        message = f"The get method was invoked with not valid input argument:\"{argument}\""
        message += (
                f". Check {api_doc} for more information. "
                f"If you still need help, open a new issue in {__github_issues_web__}."
                )

        super().__init__(message)