use serde::{Serialize, Serializer};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("Profiling is not supported on this platform")]
UnsupportedPlatform,
#[error("Profiler is already running")]
AlreadyRunning,
#[error("No profiler is currently running")]
NotRunning,
#[error("Failed to start profiler: {0}")]
StartFailed(String),
#[error("Failed to build profiler report: {0}")]
ReportFailed(String),
#[error("Failed to generate flamegraph: {0}")]
FlamegraphFailed(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Failed to resolve output path: {0}")]
PathResolution(String),
#[error("Tauri error: {0}")]
Tauri(#[from] tauri::Error),
#[error("Lock poisoned")]
LockPoisoned,
}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
pub type Result<T> = std::result::Result<T, Error>;