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
Add plugin error exception and event #2103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great start. I know the noise in the diff is annoying, but it cannot be helped.
I would suggest creating a new section to the Plugins page and document the PluginError
there. Perhaps call it Handling Errors
or something to that effect. Of course, it should link to the event and perhaps provide more context for when you would use the event. The event should probably link back to this section as well.
Tests for the Plugin API are in mkdocs/tests/plugin_tests.py. Notice that most of the tests there make use of simple events. I suggest adding an event (or two) that raises a PluginError
and a build_error
event. Then add a few tests that verify they are being called properly.
I'm not crazy about the name build_error
as it is specific to the PluginError
. The name should reflect that it handles "plugin errors." Of course, if PluginError
was a subclass of BuildError
and both were handled by the event, then that would be different. But, as I understand it, that is not the plan (although I suspect perhaps you are hoping future additions go that way). I'm open to suggestions here.
Thank you very much for your review! I will add the
This is a very good idea. I can create this |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good. With just have a few minor adjustments this should be good to go.
Note, I have not carefully reviewed the documentation. I'll do a more thorough review and make my own edits when I have the time.
Of course, no problem 🙂 |
I reviewed the docs and made some adjustments in 6568cc4. @pawamoy what you had was a great start. Its always easier to work off of something than to start with nothing. Now that I'm more familiar with the docs, I have a few thoughts:
|
Also, if you see anything in the docs that I missed, please feel free to make the changes. |
Hey @waylan, your changes to the docs are great, thanks a lot 🙂 You raised two good points indeed.
I guess it makes sense to only catch
True.
Yes we should tell that in the docs as it could be confusing ("error raised but event not called?"). Maybe we should call the event for any error then? And re-raise only if it's not a |
|
0b3feff
to
2e87017
Compare
Hello all. Sorry for coming back to this so late. I implemented what was said in the previous comments and suggestions:
The The docs were updated accordingly (they were greatly simplified by this change!). @waylan what do you think? |
FYI the whitespace change can be hidden from the diff during review. Thanks for the PR, I'm excited about it :) |
Hi @waylan, thank you for putting this in the 1.2 milestone 🙂 ! Is there anything I need to update (I see the label is still here)? Happy to help in any way. |
I just need to find the time to properly review this. |
Noted, thank you very much! |
I finally found some time to do a final review. This looks good! 👍 @pawamoy if you rebase and resolve the the conflict, I'll merge this. |
Shouldn't a merge commit be preferred over a rebase and force-push? So much easier to follow the review history then |
@oprypin you make a good point. In any event, the conflict needs to be resolved. |
Thank you for the review @waylan! I've resolved the conflicts, it should be good now. |
Oh sorry, I just realized this is missing an addition to the release notes. |
Should I take care of it? Not sure if I should add it in "Major additions" or "Other changes"? EDIT: ah, you said "missing an addition", here's my answer. |
Yes, this is adding a new feature so we should highlight it in the Major additions section. |
Just added the release notes. As always, feel free to change the wording or even the whole paragraphs! |
This PR adds a
PluginError
exception to themkdocs.exceptions
module to allow plugin writers to cleanly abort a build without showing a traceback.It also adds an
on_build_error
event that is triggered by suchPluginError
exceptions, that we catch in thebuild
command of themkdocs.commands.build
module (most of the diff in this module is just indentation in between the try/except, I could not reduce the noise). This event allows to clean things up if needed, just before aborting the build.I wondered if I should not rename the event
on_plugin_error
, but to me it makes more sense to call it a build error, because it could be triggered in other places as well. Also, if you think the event doesn't have its place in this PR, I'll gladly remove it so we can discuss it a bit more before opening (or not) another PR for it.Related: #2082 (the issue also asks for a logging error counter, as well as a
get_logger
utility function, so this PR does not resolve it entirely).TODO:
on_build_error
event, but not thePluginError
since I couldn't find an existing page documenting MkDocs exceptions. It's mentioned in theon_build_error
documentation though.