Hi Tom and Adam, I do agree that Python's chained exceptions can be confusing. Of course, when you really need that exception information to troubleshoot something, it's an absolute godsend. In any case, the way Python chains exceptions when showing them is orthogonal to this proposed change. Python already displays the exceptions chained even if we don't use "raise from", the only thing that "raise from" changes is the text that Python puts between the 2 chained exceptions.
Regarding automatically enforcing this format going forward: I looked at the list of Flake8 rules <https://www.flake8rules.com/> and couldn't find anything about it. On Sat, Jan 18, 2020 at 12:57 PM Adam Johnson <m...@adamj.eu> wrote: > Agree with Tom here. > > Is there anything we can do to control the way python displays them? > > And how would we ensure the format is kept going forwards? Is there a > flake8 rule/plugin we could activate to enforce it? > > On Sat, 18 Jan 2020 at 10:23, Tom Forbes <t...@tomforb.es> wrote: > >> I agree with this change from a correctness standpoint but I would like >> to make the point that chained exceptions might be slightly annoying when >> displayed via console output, as you see the inner exception first and have >> to scroll up to see the exception you actually have to handle. >> >> Tom >> >> On 18 Jan 2020, at 09:55, Ram Rachum <ram.rac...@gmail.com> wrote: >> >> >> >> Hi guys, >> >> I recently made a big ticket/PR to Django, and Shai Berger told me I >> should first talk about it in this mailing list. >> >> This is the ticket: https://code.djangoproject.com/ticket/31177 and its >> PR: https://github.com/django/django/pull/12339 >> >> It's a generalization of this ticket that I opened and wrote a patch for >> a few days ago: https://code.djangoproject.com/ticket/31166 It was >> discussed and merged. >> >> Basically, I think that in any place where we catch an exception, and >> then wrap it with our own exception for whatever reason, we should use the >> "raise new_exception from old_exception" syntax rather than just "raise >> new_exception". >> >> This means that when Python displays the stacktrace (and when we display >> it in the debug page,) this will make it have a text of "this exception is >> the direct result of" instead of "During handling of the above exception, >> another exception occurred". This is more accurate, because the latter >> basically means "there was an error in the process of error-handling," >> which is absolutely not the case for us, and could mislead a user. >> >> Note that we already started transitioning to "raise from", slowly: >> - Commit by Mariusz Felisiak: >> https://github.com/django/django/commit/84dcd1624784c2239f96a97b3151145a85dfbbe3 >> - Commit by Diederik van der Boor: >> https://github.com/django/django/commit/25f21bd2376603c8e233a0a0e5a726a0fdfdd33e >> - Commit by Thomas Allison: >> https://github.com/django/django/commit/3e8b7333904f1ab6aa18eeb508659256f3644816 >> >> What do you think? >> >> >> Thanks, >> Ram. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-developers+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/25086cdc-24ab-4f0a-bdb9-9756551ac170%40googlegroups.com >> <https://groups.google.com/d/msgid/django-developers/25086cdc-24ab-4f0a-bdb9-9756551ac170%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-developers+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/74BA6A05-D971-47EF-A0B6-4EF1149E83E6%40tomforb.es >> <https://groups.google.com/d/msgid/django-developers/74BA6A05-D971-47EF-A0B6-4EF1149E83E6%40tomforb.es?utm_medium=email&utm_source=footer> >> . >> > -- > Adam > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django developers (Contributions to Django itself)" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-developers/ibEOt3A9c2M/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/CAMyDDM0x0L%2Ba_r_gGL80qL3eqwMS4OV3%3Du-Hc0Wj3N1ruyQfuA%40mail.gmail.com > <https://groups.google.com/d/msgid/django-developers/CAMyDDM0x0L%2Ba_r_gGL80qL3eqwMS4OV3%3Du-Hc0Wj3N1ruyQfuA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CANXboVaOkErUiQ%2BFnRyGDp8TS-cxNbYuYh0uKms3FtJiwHF%3D7w%40mail.gmail.com.