From cd745a22d8f7501ef4966bbc6bf696bb1b63b5df Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 12 May 2025 13:57:40 +0100 Subject: [PATCH] add risc0-errors module --- crates/ere-risczero/src/error.rs | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 crates/ere-risczero/src/error.rs diff --git a/crates/ere-risczero/src/error.rs b/crates/ere-risczero/src/error.rs new file mode 100644 index 0000000..a2c7e98 --- /dev/null +++ b/crates/ere-risczero/src/error.rs @@ -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 } + } +}