Skip to main content

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 the attempt_fix method on the exception. This method, in turn, executes the on_fix_callback, providing the store 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 operates self.save_file_method, utilizing the store as an argument, potentially rectifying the predicament and facilitating the smooth progression of plugin execution.

Handling fixes in the 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.