1use std::{error, fmt, io};
2
3use crate::Layout;
4
5#[derive(Debug)]
6pub enum Error {
8 Io(io::Error),
10 Fmt(fmt::Error),
12 Format {
14 message: &'static str,
16 source: specta::FormatError,
18 },
19 ForbiddenName {
21 path: String,
23 name: String,
25 },
26 BigIntForbidden {
28 path: String,
30 },
31 UnableToExport(Layout),
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Error::Io(e) => write!(f, "IO error: {e}"),
39 Error::Fmt(e) => write!(f, "Fmt error: {e}"),
40 Error::Format { message, source } => write!(f, "Format error: {message}: {source}"),
41 Error::ForbiddenName { path, name } => {
42 write!(f, "Forbidden name: {name} in {path}")
43 }
44 Error::BigIntForbidden { path } => {
45 write!(f, "BigInt forbidden in {path}")
46 }
47 Error::UnableToExport(layout) => {
48 write!(f, "Unable to export layout: {layout:?}")
49 }
50 }
51 }
52}
53
54impl error::Error for Error {}
55
56impl From<io::Error> for Error {
57 fn from(e: io::Error) -> Self {
58 Self::Io(e)
59 }
60}
61
62impl From<fmt::Error> for Error {
63 fn from(e: fmt::Error) -> Self {
64 Self::Fmt(e)
65 }
66}
67
68impl Error {
69 pub(crate) fn format(message: &'static str, source: specta::FormatError) -> Self {
70 Self::Format { message, source }
71 }
72}