diff --git a/src/bls12_381/fq.rs b/src/bls12_381/fq.rs index e38a7ea31..177b3d76b 100644 --- a/src/bls12_381/fq.rs +++ b/src/bls12_381/fq.rs @@ -408,7 +408,7 @@ impl PrimeField for Fq { Ok(r) } else { - Err(PrimeFieldDecodingError::NotInField) + Err(PrimeFieldDecodingError::NotInField(format!("{:?}", r.0))) } } diff --git a/src/bls12_381/fr.rs b/src/bls12_381/fr.rs index 7561a56b8..2c2128fa7 100644 --- a/src/bls12_381/fr.rs +++ b/src/bls12_381/fr.rs @@ -229,7 +229,7 @@ impl PrimeField for Fr { Ok(r) } else { - Err(PrimeFieldDecodingError::NotInField) + Err(PrimeFieldDecodingError::NotInField(format!("{:?}", r.0))) } } diff --git a/src/lib.rs b/src/lib.rs index a4988d21a..c7aa7d148 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,20 +365,24 @@ pub trait PrimeFieldRepr: Sized + #[derive(Debug)] pub enum PrimeFieldDecodingError { // The encoded value is not in the field - NotInField + NotInField(String) } impl Error for PrimeFieldDecodingError { fn description(&self) -> &str { match self { - &PrimeFieldDecodingError::NotInField => "not an element in the field" + &PrimeFieldDecodingError::NotInField(..) => "not an element of the field" } } } impl fmt::Display for PrimeFieldDecodingError { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}", self.description()) + match self { + &PrimeFieldDecodingError::NotInField(ref repr) => { + write!(f, "{} is not an element of the field", repr) + } + } } }