use std::{io, num, path};
use thiserror::Error as DeriveError;
#[derive(Debug, DeriveError)]
#[non_exhaustive]
pub enum Error {
#[error("{0}")]
Resource(#[from] tauri_utils::Error),
#[error("{0:#}")]
BundlerError(#[from] anyhow::Error),
#[error("`{0}`")]
IoError(#[from] io::Error),
#[error("`{0}`")]
ImageError(#[from] image::ImageError),
#[error("`{0}`")]
WalkdirError(#[from] walkdir::Error),
#[error("`{0}`")]
StripError(#[from] path::StripPrefixError),
#[error("`{0}`")]
ConvertError(#[from] num::TryFromIntError),
#[error("`{0}`")]
ZipError(#[from] zip::result::ZipError),
#[error("`{0}`")]
HexError(#[from] hex::FromHexError),
#[error("`{0}`")]
HandleBarsError(#[from] handlebars::RenderError),
#[error("`{0}`")]
JsonError(#[from] serde_json::error::Error),
#[cfg(any(target_os = "macos", windows))]
#[error("`{0}`")]
RegexError(#[from] regex::Error),
#[error("`{0}`")]
HttpError(#[from] Box<ureq::Error>),
#[cfg(windows)]
#[error("{0}")]
GlobPattern(#[from] glob::PatternError),
#[cfg(windows)]
#[error("`{0}`")]
Glob(#[from] glob::GlobError),
#[error("`{0}`")]
UrlParse(#[from] url::ParseError),
#[error("hash mismatch of downloaded file")]
HashError,
#[error("Architecture Error: `{0}`")]
ArchError(String),
#[error("Could not find Icon paths. Please make sure they exist in the tauri config JSON file")]
IconPathError,
#[error("Could not find background file. Make sure it exists in the tauri config JSON file and extension is png/jpg/gif")]
BackgroundPathError,
#[error("Path Error:`{0}`")]
PathUtilError(String),
#[error("Shell Scripting Error:`{0}`")]
ShellScriptError(String),
#[error("`{0}`")]
GenericError(String),
#[error("Unable to find a bundled project for the updater")]
UnableToFindProject,
#[error("string is not UTF-8")]
Utf8(#[from] std::str::Utf8Error),
#[error("SignTool not found")]
SignToolNotFound,
#[error("failed to open registry {0}")]
OpenRegistry(String),
#[error("failed to get {0} value on registry")]
GetRegistryValue(String),
#[error("failed to enumerate registry keys")]
FailedToEnumerateRegKeys,
#[error("unsupported OS bitness")]
UnsupportedBitness,
#[error("failed to sign app: {0}")]
Sign(String),
#[cfg(target_os = "macos")]
#[error("`{0}`")]
TimeError(#[from] time::error::Error),
#[cfg(target_os = "macos")]
#[error(transparent)]
Plist(#[from] plist::Error),
#[cfg(target_os = "linux")]
#[error("{0}")]
RpmError(#[from] rpm::Error),
}
pub type Result<T> = std::result::Result<T, Error>;