1use miette::{Diagnostic, GraphicalReportHandler, GraphicalTheme};
2use thiserror::Error as ThisError;
3
4#[derive(Debug, ThisError, Diagnostic)]
6#[error(transparent)]
7#[diagnostic(transparent)]
8pub enum Error {
9 Connection(#[from] crate::conn::error::Error),
11 ReadQueries(#[from] crate::read_queries::error::Error),
13 ParseQueries(#[from] crate::parser::error::Error),
15 ValidateQueries(#[from] Box<crate::validation::error::Error>),
17 Container(#[from] crate::container::error::Error),
19 PrepareQueries(#[from] crate::prepare_queries::error::Error),
21 LoadSchema(#[from] crate::load_schema::error::Error),
23 WriteCodeGenFile(#[from] WriteOutputError),
25}
26
27impl Error {
28 #[must_use]
29 pub fn report(self) -> String {
30 let mut buff = String::new();
31 GraphicalReportHandler::new()
32 .with_theme(GraphicalTheme::unicode_nocolor())
33 .render_report(&mut buff, &self)
34 .unwrap();
35 buff
36 }
37}
38
39#[derive(Debug, ThisError, Diagnostic)]
40#[error("Could not write your queries to destination file `{file_path}`: ({err})")]
41pub struct WriteOutputError {
42 pub(crate) file_path: String,
43 pub(crate) err: std::io::Error,
44}