add risc0-errors module

This commit is contained in:
Kevaundray Wedderburn
2025-05-12 13:57:40 +01:00
parent cf07118c75
commit cd745a22d8

View File

@@ -0,0 +1,46 @@
use std::{io, path::PathBuf, process::ExitStatus};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum RiscZeroError {
#[error(transparent)]
Compile(#[from] CompileError),
}
#[derive(Debug, Error)]
pub enum CompileError {
#[error("{context}: {source}")]
Io {
#[source]
source: io::Error,
context: &'static str,
},
#[error("{context}: {source}")]
SerdeJson {
#[source]
source: serde_json::Error,
context: &'static str,
},
#[error("Methods crate path does not exist or is not a directory: {0}")]
InvalidMethodsPath(PathBuf),
#[error(
"`cargo build` for {crate_path} failed with status {status}\nstdout:\n{stdout}\nstderr:\n{stderr}"
)]
CargoBuildFailure {
crate_path: PathBuf,
status: ExitStatus,
stdout: String,
stderr: String,
},
#[error("Could not find field `{field}` in JSON file `{file}`")]
MissingJsonField { field: &'static str, file: PathBuf },
}
impl CompileError {
pub fn io(e: io::Error, context: &'static str) -> Self {
Self::Io { source: e, context }
}
pub fn serde(e: serde_json::Error, context: &'static str) -> Self {
Self::SerdeJson { source: e, context }
}
}