use std::process::Command;
use std::sync::Arc;
use gds::GdsError;
use crate::layout::error::{GdsImportError, LayoutError};
use crate::schematic::conv::ConvError;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
#[error("error in layout: {0:?}")]
Layout(LayoutError),
#[error("I/O error: {0}")]
Io(#[from] Arc<std::io::Error>),
#[error("internal Substrate error")]
Internal,
#[error(transparent)]
CacheError(#[from] Arc<cache::error::Error>),
#[error("a thread panicked")]
Panic,
#[error("error executing command: {0:?}")]
CommandFailed(Arc<Command>),
#[error("gds error: {0}")]
Gds(#[from] GdsError),
#[error("error importing GDS: {0}")]
GdsImport(#[from] GdsImportError),
#[error(transparent)]
Boxed(#[from] Arc<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
Anyhow(#[from] Arc<anyhow::Error>),
#[error("error converting to SCIR: {0}")]
ScirConversion(#[from] ConvError),
#[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)
}
}