From d66b5c42a05fec352593a34d4f26a9799165cdc5 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 4 Nov 2021 13:38:38 +0000 Subject: [PATCH] `impl std::error::Error for Error` --- CHANGELOG.md | 1 + src/plonk/error.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49459e62..ebd97dee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to Rust's notion of ## [Unreleased] ### Changed - `halo2::plonk::Error` has been overhauled: + - `Error` now implements `std::fmt::Display` and `std::error::Error`. - `Error` no longer implements `PartialEq`. Tests can check for specific error cases with `assert!(matches!(..))`. - `Error::IncompatibleParams` is now `Error::InvalidInstances`. diff --git a/src/plonk/error.rs b/src/plonk/error.rs index 7058f79b..18f695e3 100644 --- a/src/plonk/error.rs +++ b/src/plonk/error.rs @@ -1,3 +1,5 @@ +use std::error; +use std::fmt; use std::io; /// This is an error that could occur during proving or circuit synthesis. @@ -32,3 +34,33 @@ impl From for Error { Error::Transcript(error) } } + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::Synthesis => write!(f, "General synthesis error"), + Error::InvalidInstances => write!(f, "Provided instances do not match the circuit"), + Error::ConstraintSystemFailure => write!(f, "The constraint system is not satisfied"), + Error::BoundsFailure => write!(f, "An out-of-bounds index was passed to the backend"), + Error::Opening => write!(f, "Multi-opening proof was invalid"), + Error::Transcript(e) => write!(f, "Transcript error: {}", e), + Error::NotEnoughRowsAvailable => write!(f, "`k` is too small for the given circuit"), + Error::InstanceTooLarge => write!(f, "Instance vectors are larger than the circuit"), + Error::NotEnoughColumnsForConstants => { + write!( + f, + "Too few fixed columns are enabled for global constants usage" + ) + } + } + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + match self { + Error::Transcript(e) => Some(e), + _ => None, + } + } +}