Plugin Logic
Plugin Execution
In addition to engine execution, the BaseEngine
class facilitates individual plugin execution through the run_plugin
method. This method's responsibilities encompass:
- Initialization of the plugin with specified options.
- Execution of the plugin's
run
method, incorporating the plugin store as a parameter.
Plugin Execution Flow
The execution of a plugin involves a structured sequence:
- Retrieval of the registered plugin from the plugin registry.
- Instantiation of the plugin using the provided options.
- Execution of the plugin's
run
method. - Management of exceptions arising during the plugin's execution.
- Logging of both the execution time and the resulting output.
Plugin Error Handling
The plugin execution process is not immune to errors, leading to exceptions such as PluginExecutionError
, PluginValidationError
, and PluginUIHookExecutionError
. The run_plugin
method addresses these scenarios by:
- Logging the encountered error.
- Updating the status within the plugin info.
- Potentially invoking an
EngineExecutionError
depending on the situation.
PluginValidationError and Automatic Fix
PluginValidationError
represents a unique exception class, triggered when a plugin's preconditions are unmet. This typically occurs when the requisite data is absent or malformed.
raise PluginValidationError(
message='File not saved. Click fix to save it.',
on_fix_callback=self.save_file_method,
)
Automatic Fix Method
The architecture of PluginValidationError
includes an on_fix_callback
method, which is:
- Error Resolution: A designated callback intended to autonomously rectify the validation error.
- Fix Invocation: Upon encountering a
PluginValidationError
, the engine can activate theattempt_fix
method on the exception. This method, in turn, executes theon_fix_callback
, providing thestore
and any additional parameters as arguments.
Example of Automatic Fix
Consider a scenario where a plugin identifies an unsaved requisite file:
- Error Initiation: The plugin raises a
PluginValidationError
, attaching a fix callback aimed at saving the file. - Fix Execution: When the
attempt_fix
method is invoked, it operatesself.save_file_method
, utilizing thestore
as an argument, potentially rectifying the predicament and facilitating the smooth progression of plugin execution.
Handling Fixes in Engine
The BaseEngine
class is designed to manage PluginValidationError
by:
- Fix Application: Attempting to implement the proposed fix.
- Status Re-evaluation: Post-fix application, the engine reassesses the plugin's status to ensure compliance with the expected conditions.
Through this mechanism, the framework not only enables plugins to signal validation concerns but also empowers them to propose and execute corrective measures autonomously. This functionality significantly enhances the execution flow and enriches the user experience by ensuring a more seamless and responsive plugin operation.
PluginInfo
The PluginInfo
class is designed to encapsulate various details pertaining to plugin execution, including aspects like name, reference, options, store, status, message, and execution time.
Plugin Event Callbacks
The BaseEngine
class also accommodates the specification of an event callback, which is invoked post-plugin execution. This feature is instrumental for conducting additional operations or logging based on the execution outcome.