snarkvm_curves/
errors.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#[derive(Debug, Error)]
17pub enum GroupError {
18    #[error("{}: {}", _0, _1)]
19    Crate(&'static str, String),
20
21    #[error("{}", _0)]
22    FieldError(snarkvm_fields::FieldError),
23
24    #[error("Invalid group element")]
25    InvalidGroupElement,
26
27    #[error("Attempting to parse an invalid string into a group element")]
28    InvalidString,
29
30    #[error("{}", _0)]
31    Message(String),
32
33    #[error("Attempting to parse an empty string into a group element")]
34    ParsingEmptyString,
35
36    #[error("Attempting to parse a non-digit character into a group element")]
37    ParsingNonDigitCharacter,
38}
39
40impl From<snarkvm_fields::FieldError> for GroupError {
41    fn from(error: snarkvm_fields::FieldError) -> Self {
42        GroupError::FieldError(error)
43    }
44}
45
46impl From<std::io::Error> for GroupError {
47    fn from(error: std::io::Error) -> Self {
48        GroupError::Crate("std::io", format!("{error:?}"))
49    }
50}
51
52impl From<GroupError> for std::io::Error {
53    fn from(error: GroupError) -> Self {
54        std::io::Error::other(format!("{error}"))
55    }
56}