use crate::{InterpretError, ParseError, ScanError};
use miette::Diagnostic;
use std::io;
use thiserror::Error;

/// Common Nexus error type with `miette` diagnostic support.
#[derive(Debug, Error, Diagnostic)]
pub enum NexusError {
    #[error("Scan error")]
    #[diagnostic(transparent)]
    Scan(#[from] ScanError),

    #[error("Parse error")]
    #[diagnostic(transparent)]
    Parse(#[from] ParseError),

    #[error("Interpret error")]
    #[diagnostic(transparent)]
    Interpret(#[from] InterpretError),

    #[error("I/O error: {0}")]
    #[diagnostic(
        code(nexus_lang::io_error),
        help("Check that the file exists and you have permission to read it")
    )]
    Io(#[from] io::Error),
}
