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

Deprecated message property for exceptions is used #119

Closed
meliache opened this issue Jul 28, 2021 · 2 comments · Fixed by #120
Closed

Deprecated message property for exceptions is used #119

meliache opened this issue Jul 28, 2021 · 2 comments · Fixed by #120
Assignees
Labels
bug Something isn't working

Comments

@meliache
Copy link
Collaborator

meliache commented Jul 28, 2021

In b2luigi.core.utils.map_folder an exception is re-raised with a modified exception message, where the original message is appended viaex.message.

    except AttributeError as ex:
        raise type(ex)(
            "Could not determine the current script location. "
            "If you are running in an interactive shell (such as jupyter notebook) "
            "make sure to only provide absolute paths in your settings.\nMore Info:\n" +
            ex.message
        ).with_traceback(sys.exc_info()[2])

I get an error in python 3.9 that the exception has no message property, but this seems to be already deprecated since python 2.6 (see PEP-352).

The obvious solution would be to just use the str(ex) or a format string like f"More info: {ex}". But before fixing this in a PR, my questions is what's the "best" way to re-raise an exception with a modified message in python 3. The raise type(ex)(...).with_traceback(...) construct seems a bit cumbersome to me, is it really necessary? I admit I don't fully understand it, maybe @FelixMetzner who introduced this code in #34 (thanks for that) can help.

@meliache meliache added the bug Something isn't working label Jul 28, 2021
@meliache meliache self-assigned this Jul 28, 2021
@nils-braun
Copy link
Owner

If you raise an exception within handling another exception, both stack traces and exception messages will be shown (... while handling ...).
You can also choose what is shown with something like raise Ex1 from Ex2, but that should not be necessary here (as the outer exception is the default)

@meliache
Copy link
Collaborator Author

meliache commented Jul 30, 2021

If you raise an exception within handling another exception, both stack traces and exception messages will be shown (... while handling ...).

I saw this when the bug occured, then I got another exception that ex.message doesn't exist 😉

I'll then go forward with the suggested fix.

meliache added a commit that referenced this issue Jul 30, 2021
That property is deprecated since python 2.6, see PEP-352 [1].

Solves issue #119 [2].

[1]: https://www.python.org/dev/peps/pep-0352/#retracted-ideas
[2]: #119
@meliache meliache linked a pull request Jul 30, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants