vyper_rs/
vyper_errors.rs

1//! This module contains the main error type returned when there's some issue with the compiler in
2//! the Vyper module.
3use std::{error::Error, fmt::Display, io, num::ParseIntError};
4
5#[derive(Debug)]
6pub enum VyperErrors {
7    IoError(io::Error),
8    CompilerError(String),
9    SerializationError(serde_json::Error),
10    ConcurrencyError(tokio::task::JoinError),
11    PipError(String),
12    DirError(String),
13    VenvError(String),
14    BlueprintError(String),
15    IntParseError(ParseIntError),
16    StringParsingError,
17}
18
19impl Display for VyperErrors {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            VyperErrors::IoError(err) => {
23                write!(f, "An error occured while using system IO: {}", err)
24            }
25            VyperErrors::SerializationError(s) => write!(
26                f,
27                "An error occurred while serializing or deserializing data: {}",
28                s,
29            ),
30            VyperErrors::CompilerError(msg) => write!(f, "{}", msg),
31            VyperErrors::PipError(msg) => write!(f, "{}", msg),
32            VyperErrors::ConcurrencyError(je) => {
33                write!(f, "Failed to join async tasks: {}", je)
34            }
35            VyperErrors::DirError(msg) => write!(f, "{}", msg),
36            VyperErrors::VenvError(msg) => write!(f, "{}", msg),
37            VyperErrors::BlueprintError(msg) => write!(f, "{}", msg),
38            VyperErrors::IntParseError(e) => write!(f, "{}", e),
39            VyperErrors::StringParsingError => write!(
40                f,
41                "An error occurred while parsing bytecode from vyper compiler output"
42            ),
43        }
44    }
45}
46
47impl Error for VyperErrors {}
48
49impl From<std::io::Error> for VyperErrors {
50    fn from(value: std::io::Error) -> Self {
51        VyperErrors::IoError(value)
52    }
53}
54
55impl From<serde_json::Error> for VyperErrors {
56    fn from(value: serde_json::Error) -> Self {
57        VyperErrors::SerializationError(value)
58    }
59}
60
61impl From<tokio::task::JoinError> for VyperErrors {
62    fn from(value: tokio::task::JoinError) -> Self {
63        VyperErrors::ConcurrencyError(value)
64    }
65}