use std::{path::PathBuf, string::FromUtf8Error};
use fluent_i18n::t;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
AlpmType(#[from] alpm_types::Error),
#[error(transparent)]
InvalidUTF8(#[from] FromUtf8Error),
#[error("{msg}", msg = t!("error-io", {
"context" => context,
"source" => source.to_string()
}))]
Io {
context: String,
source: std::io::Error,
},
#[error("{msg}", msg = t!("error-io-path", {
"path" => path,
"context" => context,
"source" => source.to_string()
}))]
IoPath {
path: PathBuf,
context: String,
source: std::io::Error,
},
#[error("{msg}", msg = t!("error-invalid-file", {
"path" => path,
"context" => context
}))]
InvalidFile {
path: PathBuf,
context: String,
},
#[error("{msg}", msg = t!("error-script-not-found", {
"script_name" => script_name,
"source" => source.to_string()
}))]
ScriptNotFound {
script_name: String,
source: which::Error,
},
#[error("{msg}", msg = t!("error-script-failed-start", {
"context" => context,
"parameters" => format!("{parameters:?}"),
"source" => source.to_string()
}))]
Script {
context: String,
parameters: Vec<String>,
source: std::io::Error,
},
#[error("{msg}", msg = t!("error-script-execution", {
"parameters" => format!("{parameters:?}"),
"stdout" => stdout,
"stderr" => stderr
}))]
ScriptExecution {
parameters: Vec<String>,
stdout: String,
stderr: String,
},
#[error("{msg}", msg = t!("error-bridge-parse", { "error" => .0 }))]
BridgeParseError(String),
#[error("{msg}", msg = t!("error-json", { "source" => .0.to_string() }))]
Json(#[from] serde_json::Error),
}