Skip to content

fix!: Raise exceptions when a plugin fails to load. - #1377

Open
xitij2000 wants to merge 1 commit into
overhangio:mainfrom
open-craft:kshitij/error-on-missing-plugin
Open

xitij2000 wants to merge 1 commit into
overhangio:mainfrom
open-craft:kshitij/error-on-missing-plugin

Conversation

@xitij2000

Copy link
Copy Markdown
Contributor

When a plugin is missing or throws an error while loading, Tutor continues as normal. At times this has made us recognise issues far later than we'd like.

This change will raise an error causing the command to return an error and the break the CI flow rather than deploying a broken instance with missing plugins.

We've considered few alternatives.

  1. Put this behind an option flag such as --check, however this flag would need to be added in a lot of places that cause plugins to load.
  2. Adding another command like tutor doctor this is a convention that many such tools follow that check the config and environment for errors and suggest fixes. This issue with this is that it will require updating existing usage of tutor to call tutor doctor first.
  3. Creating a plugin for this. We think this is a core feature hat should be part of tutor, but this could potentially be done in a plugin.

@xitij2000

Copy link
Copy Markdown
Contributor Author

Note this PR is to get the conversation started, we can improve the error messaging etc.

@Kelketek

Copy link
Copy Markdown
Contributor

@xitij2000 It looks like you can't disable the plugin using the command line after running into this problem. I could try modifying the config, but I can't ask it for the config root, either. Is it possible to keep this a warning for configuration commands but an error for things like image building and launching?

@xitij2000

xitij2000 commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@xitij2000 It looks like you can't disable the plugin using the command line after running into this problem. I could try modifying the config, but I can't ask it for the config root, either. Is it possible to keep this a warning for configuration commands but an error for things like image building and launching?

I'll look into that. For now I just wanted to get some feedback. Is there is a reason to not do this at all? Or move it to a separate command or plugin.

@ahmed-arb

Copy link
Copy Markdown
Collaborator

The fail-fast goal makes sense, but raising at the plugin-loading layer is too low: ensure_plugins_enabled runs on every invocation, so a plugin that fails to load doesn't just break launch; it also breaks:

  • tutor plugins disable <bad-plugin>
  • tutor config
  • tutor --help

The commands you'd use to recover all trigger plugin loading first, so the user gets bricked into hand-editing config.yml or running pip uninstall (which is what @Kelketek hit above).

Also worth noting: the raise lives inside the for name in names loop in load_all, so the first failing plugin aborts loading of all remaining plugins and skips PLUGINS_LOADED.do(). As a result, one broken plugin takes down healthy ones too.

I'd suggest keeping loading (warn + record failures) and moving the hard failure up to deployment/build commands (launch, start, images build) while leaving inspection/recovery commands as warnings.

@xitij2000

Copy link
Copy Markdown
Contributor Author

@ahmed-arb Thanks for having a look!

I agree with all the points you have raised, I just wanted to start discussing this issue with this PR. I plan to make the solution more robust when I get back to this.

@Abdul-Muqadim-Arbisoft Abdul-Muqadim-Arbisoft moved this from Pending Triage to Backlog in Tutor project management Jun 23, 2026
@xitij2000
xitij2000 force-pushed the kshitij/error-on-missing-plugin branch from 9e3d63d to a865182 Compare July 3, 2026 12:03
Comment thread tests/commands/test_cli.py Outdated
def test_check_plugin_errors_exits_with_code_1(self) -> None:
"""_check_plugin_errors should exit with code 1 when errors exist."""
self._add_plugin_error()
with self.assertRaises(SystemExit) as cm:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, cool. I didn't know you could catch sys.exit like this.

@Kelketek

Kelketek commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@xitij2000 Thanks for these updates. Image building succeeds, though it should be one of the commands that fails if an enabled plugin is missing, in my opinion. Actually, launch also gets off the ground right now. Can you double-check that things are actually failing for you where they need to be?

CI is also failing.

You noted to me over our internal ticket that this set of errors would cause a freshly installed tutor launch to fail due to installing only tutor leaving out plugins like mfe and indigo. However, I actually think this is preferable-- if someone accidentally installs only tutor and launches a brand new install, they're not following the tutorial closely and have almost certainly made a mistake.

Anyone who is deliberately only installing Tutor will know what to do about this because they'll be familiar, and it's very likely they already have a config.yml file without those entries in the plugin list.

@xitij2000

Copy link
Copy Markdown
Contributor Author

@xitij2000 Thanks for these updates. Image building succeeds, though it should be one of the commands that fails if an enabled plugin is missing, in my opinion. Actually, launch also gets off the ground right now. Can you double-check that things are actually failing for you where they need to be?

CI is also failing.

You noted to me over our internal ticket that this set of errors would cause a freshly installed tutor launch to fail due to installing only tutor leaving out plugins like mfe and indigo. However, I actually think this is preferable-- if someone accidentally installs only tutor and launches a brand new install, they're not following the tutorial closely and have almost certainly made a mistake.

Anyone who is deliberately only installing Tutor will know what to do about this because they'll be familiar, and it's very likely they already have a config.yml file without those entries in the plugin list.

Now command should run but produce an error at the end and return a error code. While this is not ideal, raising an error first means that you can't even run a command to fix the error, as was the case before.

This way if you apply a config change and that raises a plugin error it will raise immediately.

While I agree about the missing plugins raising an error by default it is a breaking change and I'd want some upstream feedback on this.

@xitij2000
xitij2000 force-pushed the kshitij/error-on-missing-plugin branch from a865182 to 5c0994e Compare August 20, 2026 08:25
@xitij2000
xitij2000 marked this pull request as ready for review August 20, 2026 17:01

@Kelketek Kelketek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xitij2000 It is indeed failing commands after running them if there is a plugin error. However, I'm still unhappy with it going all the way through commands like image building and launching. It greatly undermines the utility of the change, as the original reason we bothered with this at all was to avoid waiting hours just to find out that the build couldn't be correct.

Note also that if an image building succeeds, that image is saved, and so it will be the image rolled next restart. Someone could deploy an image they don't want to because they haven't fixed it and rebuilt. That shouldn't be possible-- if the configuration is bad and we're returning an error code, we don't want the state to be left worse than when we found it.

You mentioned needing input from upstream on this, bearing in mind that the default settings would break in the case that someone installed Tutor and initialized a new configuration while not following the tutorial and instead running the commands raw. I'm still of the mind that this is fine, given my reasoning above.

However, I want to ping @ahmed-arb and get his take. @ahmed-arb , what are your thoughts on my suggestions here?

Comment thread tutor/commands/cli.py Outdated
# Only exit with an error code if:
# - errors are not being ignored
# - the config file hasn't changed
# - no exception has already been raised that would return its own error codek

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# - no exception has already been raised that would return its own error codek
# - no exception has already been raised that would return its own error code

@xitij2000

Copy link
Copy Markdown
Contributor Author

@Kelketek I think the only solution for this is to special case certain commands to run despite plugin errors, such as config editing, and enabling / disabling plugins.

@Kelketek

Copy link
Copy Markdown
Contributor

@xitij2000 Maybe it could be done by a special 'configuration_exempt' decorator which adds an attribute to the function which the preflight can check for? That way any other plugin that includes a command that should be able to run with broken plugins can use it.

@xitij2000

Copy link
Copy Markdown
Contributor Author

@Kelketek I think that approach makes sense. The decorator can simply add an attribute to the function which can be looked up and for functions that are marked this way we can skip the early exit.

@Faraz32123
Faraz32123 requested a review from ahmed-arb September 8, 2026 09:24

@ahmed-arb ahmed-arb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you please update your branch?

@Abdul-Muqadim-Arbisoft

Copy link
Copy Markdown
Collaborator

@xitij2000 Can you please update your branch?, in case if you don't have capacity we can take care of it

@xitij2000

Copy link
Copy Markdown
Contributor Author

@Abdul-Muqadim-Arbisoft Sorry for the delay, this slipped off my mind. I'll aim to update the PR with the latest suggestions asap.

@xitij2000
xitij2000 force-pushed the kshitij/error-on-missing-plugin branch from fc8edb9 to 4716fde Compare November 14, 2026 06:57
@xitij2000

Copy link
Copy Markdown
Contributor Author

@Abdul-Muqadim-Arbisoft @Kelketek I've made this into a decorator, do have a look.

@xitij2000
xitij2000 force-pushed the kshitij/error-on-missing-plugin branch from 4716fde to acd9946 Compare November 16, 2026 11:43
Rather than continue and potentially deploy a broken instance,
this change make commands fail early so issues can be detected
sooner rather than later.

A new `hooks.Filters.PLUGIN_ERRORS` filer gathers all plugin
errors. In case of errors the Tutor will now abort listing
these plugins errors.

Commands that cane be helpful in resolving errors, such as
plugin, config and help are exempt from this. Additionally,
there is a global `--ignore-plugin-errors` flag to ignore all
errors.
@xitij2000
xitij2000 force-pushed the kshitij/error-on-missing-plugin branch from acd9946 to 1a1225e Compare November 16, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants