-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Refactor error handling to leverage thiserror's automatic Displa…
…y implementation (#329)
- Loading branch information
Showing
1 changed file
with
6 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,37 @@ | ||
use std::fmt::Display; | ||
use thiserror::Error; | ||
|
||
/// Errors that occur during dynamic compilation of guest programs. | ||
#[derive(Debug, Error)] | ||
pub enum BuildError { | ||
/// The compile options are invalid for the memory limit. | ||
#[error("invalid memory configuration for selected prover")] | ||
InvalidMemoryConfiguration, | ||
|
||
/// An error occurred reading or writing to the file system. | ||
#[error(transparent)] | ||
IOError(#[from] std::io::Error), | ||
|
||
/// The compilation process failed. | ||
#[error("unable to compile using rustc")] | ||
CompilerError, | ||
} | ||
|
||
impl Display for BuildError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::InvalidMemoryConfiguration => { | ||
write!(f, "invalid memory configuration for selected prover") | ||
} | ||
Self::IOError(error) => write!(f, "{}", error), | ||
Self::CompilerError => write!(f, "unable to compile using rustc"), | ||
} | ||
} | ||
} | ||
|
||
/// Errors that occur while reading from or writing to the input/output tapes of the zkVM. | ||
#[derive(Debug, Error)] | ||
pub enum TapeError { | ||
/// Error serializing to or deserializing from the zkVM input/output tapes. | ||
#[error("serialization error: {0}")] | ||
SerializationError(#[from] postcard::Error), | ||
|
||
/// Error parsing logging tape. | ||
#[error("encoding error: {0}")] | ||
EncodingError(#[from] std::string::FromUtf8Error), | ||
} | ||
|
||
impl Display for TapeError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::SerializationError(error) => write!(f, "{}", error), | ||
Self::EncodingError(error) => write!(f, "{}", error), | ||
} | ||
} | ||
} | ||
|
||
/// Errors that occur when processing file paths. | ||
#[derive(Debug, Error)] | ||
pub enum PathError { | ||
/// Invalid encoding used for path. | ||
#[error("provided path has invalid encoding for use with filesystem")] | ||
EncodingError, | ||
} | ||
|
||
impl Display for PathError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::EncodingError => write!( | ||
f, | ||
"provided path has invalid encoding for use with filesystem" | ||
), | ||
} | ||
} | ||
} |