-
Notifications
You must be signed in to change notification settings - Fork 2
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
Gracefully handle bad plugins? #37
Comments
tutor plugins ...
CLI
Just to clarify: the first time that we run
But any further CLI command makes a call to
In particular, the I'm not sure what's the right solution here. I don't think we should wrap the plugin loading step in |
can we use some sort of validation mechanism for python plugins? def validate_plugin(plugin_path):
try:
# Check for syntax errors
with open(plugin_path, "r") as plugin_file:
exec(plugin_file.read())
except SyntaxError as e:
return False, f"Syntax error in plugin: {str(e)}"
except ImportError as e:
return False, f"Missing import in plugin: {str(e)}"
except Exception as e:
return False, f"Unknown error in plugin: {str(e)}"
return True, "" and on enable side maybe something like this: def enable_plugin(plugin_name):
plugin_path = os.path.join(tutor.plugins.printroot(), plugin_name + ".py")
is_valid, error_message = validate_plugin(plugin_path)
if not is_valid:
print(f"Error: Plugin '{plugin_name}' is not valid: {error_message}")
sys.exit(1)
# Continue with enabling the plugin |
I'm not a big fan of the
But this is exactly the code that's in place right now. So I'm not 100% what we should do differently, and most importantly: why? Which issue are we trying to address exactly? |
Reproduction Steps
$(tutor plugins printroot)/mybadplugin.py
tutor plugins enable mybadplugin
, which should cause an exception (not surprisingly).tutor plugins printroot
. Notice that it exits nonzero and does not print your plugin root (this is the "bug").Now, I'm not sure how or even if we should try to guard the CLI against all malformed plugins. Wrapping every command in a try-except would probably be overkill. On the other hand, it might be smart to insulate the
tutor plugins ...
CLI in particular from bad plugins, since the CLI might help the user in disabling/editing the bad plugin.Acceptance
TBD
The text was updated successfully, but these errors were encountered: