substrate/
error.rs

1//! Error types and error handling utilities.
2
3use std::process::Command;
4use std::sync::Arc;
5
6use gds::GdsError;
7
8use crate::layout::conv::LayirExportError;
9use crate::layout::error::{GdsImportError, LayoutError};
10use crate::schematic::conv::ConvError;
11
12/// A result type returning Substrate errors.
13pub type Result<T, E = Error> = std::result::Result<T, E>;
14
15/// The error type for Substrate functions.
16#[derive(thiserror::Error, Debug, Clone)]
17pub enum Error {
18    /// An error in a layout-related routine.
19    #[error("error in layout: {0:?}")]
20    Layout(LayoutError),
21    /// An I/O error.
22    #[error("I/O error: {0}")]
23    Io(#[from] Arc<std::io::Error>),
24    /// An internal Substrate error that indicates a bug in the source code.
25    #[error("internal Substrate error")]
26    Internal,
27    /// An error indicating that one or more fatal errors occured while building a cell.
28    #[error("fatal errors occured while building cell")]
29    CellBuildFatal,
30    /// An error thrown by caching functions.
31    #[error(transparent)]
32    CacheError(#[from] Arc<cache::error::Error>),
33    /// An error thrown when a thread spawned during generation panics.
34    #[error("a thread panicked")]
35    Panic,
36    /// Executing a command failed.
37    #[error("error executing command: {0:?}")]
38    CommandFailed(Arc<Command>),
39    /// GDS error.
40    #[error("gds error: {0}")]
41    Gds(#[from] GdsError),
42    /// Error importing GDS.
43    #[error("error importing GDS: {0}")]
44    GdsImport(#[from] GdsImportError),
45    /// An arbitrary error for external use.
46    #[error(transparent)]
47    Boxed(#[from] Arc<dyn std::error::Error + Send + Sync>),
48    /// An [`anyhow::Error`] for external use.
49    #[error(transparent)]
50    Anyhow(#[from] Arc<anyhow::Error>),
51    /// Schematic to SCIR conversion produced errors.
52    #[error("error converting to SCIR: {0}")]
53    ScirConversion(#[from] ConvError),
54    /// An error indicating that the schema does not support an instantiated primitive.
55    #[error("schema does not support primitive")]
56    UnsupportedPrimitive,
57    /// Indicates an error exporting a layout cell to LayIR.
58    #[error("error exporting to LayIR")]
59    LayirExport(#[from] LayirExportError),
60}
61
62impl From<std::io::Error> for Error {
63    fn from(value: std::io::Error) -> Self {
64        Self::Io(Arc::new(value))
65    }
66}
67
68impl From<LayoutError> for Error {
69    fn from(value: LayoutError) -> Self {
70        Error::Layout(value)
71    }
72}