1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Error types and error handling utilities.

use std::process::Command;
use std::sync::Arc;

use gds::GdsError;

use crate::layout::error::{GdsImportError, LayoutError};
use crate::schematic::conv::ConvError;

/// A result type returning Substrate errors.
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// The error type for Substrate functions.
#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
    /// An error in a layout-related routine.
    #[error("error in layout: {0:?}")]
    Layout(LayoutError),
    /// An I/O error.
    #[error("I/O error: {0}")]
    Io(#[from] Arc<std::io::Error>),
    /// An internal Substrate error that indicates a bug in the source code.
    #[error("internal Substrate error")]
    Internal,
    /// An error thrown by caching functions.
    #[error(transparent)]
    CacheError(#[from] Arc<cache::error::Error>),
    /// An error thrown when a thread spawned during generation panics.
    #[error("a thread panicked")]
    Panic,
    /// Executing a command failed.
    #[error("error executing command: {0:?}")]
    CommandFailed(Arc<Command>),
    /// GDS error.
    #[error("gds error: {0}")]
    Gds(#[from] GdsError),
    /// Error importing GDS.
    #[error("error importing GDS: {0}")]
    GdsImport(#[from] GdsImportError),
    /// An arbitrary error for external use.
    #[error(transparent)]
    Boxed(#[from] Arc<dyn std::error::Error + Send + Sync>),
    /// An [`anyhow::Error`] for external use.
    #[error(transparent)]
    Anyhow(#[from] Arc<anyhow::Error>),
    /// Schematic to SCIR conversion produced errors.
    #[error("error converting to SCIR: {0}")]
    ScirConversion(#[from] ConvError),
    /// An error indicating that the schema does not support an instantiated primitive.
    #[error("schema does not support primitive")]
    UnsupportedPrimitive,
}

impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Self::Io(Arc::new(value))
    }
}

impl From<LayoutError> for Error {
    fn from(value: LayoutError) -> Self {
        Error::Layout(value)
    }
}