use std::io;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum FormatJsonError {
#[error("File {0} not found")]
FileNotFound(String),
#[error("{0}")]
IOError(#[from] io::Error),
#[error("{0}")]
InvalidSyntax(#[from] InvalidSyntaxDiagnostic),
#[error("{0}")]
Unknown(String),
}
#[derive(Error, Debug, miette::Diagnostic)]
#[error("{error_message}")]
pub struct InvalidSyntaxDiagnostic {
#[source_code]
src: miette::NamedSource<String>,
#[label("Error here")]
bad_bit: miette::SourceSpan,
error_message: String,
}
impl InvalidSyntaxDiagnostic {
pub fn new(
filepath: &str,
src: &str,
bad_bit: miette::SourceSpan,
error_message: String,
) -> Self {
Self {
src: miette::NamedSource::new(filepath, src.to_string()),
bad_bit,
error_message,
}
}
}