1use std::path::PathBuf;
4
5use thiserror::Error;
6
7#[derive(Debug, Error)]
9pub enum PluginError {
10 #[error("failed to parse plugin source at {path}: {message}")]
12 InvalidSource { path: PathBuf, message: String },
13 #[error("plugin {plugin} does not expose version {version}")]
15 VersionNotFound { plugin: String, version: String },
16 #[error("plugin did not provide a result")]
18 NoResultProvided,
19 #[error("plugin backend error: {0}")]
21 Backend(String),
22}
23
24pub type PluginResult<T> = Result<T, PluginError>;
26
27pub trait IntoPluginResult<T> {
29 fn into_plugin_result(self) -> Result<T, PluginError>;
30}
31
32impl<T, E: std::fmt::Display> IntoPluginResult<T> for Result<T, E> {
33 fn into_plugin_result(self) -> Result<T, PluginError> {
34 self.map_err(|error| PluginError::Backend(error.to_string()))
35 }
36}