use serde::Serialize;
use thiserror::Error;
#[derive(Debug, Error, Serialize)]
pub enum RbatError {
#[error("I/O error occurred")]
Io(
#[from]
#[serde(serialize_with = "serialize_to_string")]
std::io::Error,
),
#[error("Error occurred while parsing binary")]
ParseError(
#[from]
#[serde(serialize_with = "serialize_to_string")]
goblin::error::Error,
),
#[error("Error occurred while disassembling binary bytes")]
DisassemblerError(
#[from]
#[serde(serialize_with = "serialize_to_string")]
capstone::Error,
),
#[error("Error occurred while compiling YARA rules")]
YaraCompileError(
#[from]
#[serde(serialize_with = "serialize_to_string")]
yara::errors::YaraError,
),
#[error("Error occurred while performing I/O with YARA")]
YaraIO(
#[from]
#[serde(serialize_with = "serialize_to_string")]
yara::Error,
),
#[error("Serialization error")]
SerializationError(
#[from]
#[serde(serialize_with = "serialize_to_string")]
serde_json::Error,
),
#[error("CLI error")]
CliError(
#[from]
#[serde(serialize_with = "serialize_to_string")]
clap::error::Error,
),
#[error("Unsupported binary format: {0}")]
UnsupportedBinaryFormat(String),
#[error("Invalid binary layout: {0}")]
InvalidBinaryLayout(String),
#[error("Missing executable section in binary")]
MissingExecutableSection,
#[error("Missing required embedded asset: {0}")]
MissingAsset(String),
#[error("Missing analysis data: {0}")]
MissingAnalysisData(String),
#[error("Invalid UTF-8 in embedded asset")]
Utf8Error(
#[from]
#[serde(serialize_with = "serialize_to_string")]
std::string::FromUtf8Error,
),
#[error("csv creation error")]
ErrorCreatingCsv(
#[from]
#[serde(serialize_with = "serialize_to_string")]
csv::Error,
),
#[error("an error occurred which resulted in the cancellation of the analysis process")]
ErrorAnalysisCancelled,
#[error("HTML template rendering error: {0}")]
TemplateError(String),
#[error("PDF rendering error: {0}")]
PdfRenderError(String),
#[error("JSON error: {0}")]
JsonError(String),
#[error("CSV error: {0}")]
CsvError(String),
}
fn serialize_to_string<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: std::fmt::Display,
S: serde::Serializer,
{
serializer.serialize_str(&value.to_string())
}