use std::io as StdIO;
use std::path::PathBuf;
use miette::Diagnostic;
use serde_json as SJSON;
use thiserror::Error as ThisError;
#[derive(Debug, Diagnostic, ThisError)]
pub enum Error {
#[error("Failed to read file")]
#[diagnostic(
code(docs_md::io::read),
help("Check that the file exists and is readable")
)]
FileRead(#[source] StdIO::Error),
#[error("Failed to parse rustdoc JSON")]
#[diagnostic(
code(docs_md::parse::json),
help("Ensure the file is valid rustdoc JSON output (generated with --output-format json)")
)]
JsonParse(#[source] SJSON::Error),
#[cfg(feature = "simd-json")]
#[error("Failed to parse rustdoc JSON (simd-json)")]
#[diagnostic(
code(docs_md::parse::simd_json),
help("Ensure the file is valid rustdoc JSON output (generated with --output-format json)")
)]
SimdJsonParse(#[source] simd_json::Error),
#[error("Failed to create output directory")]
#[diagnostic(code(docs_md::io::mkdir))]
CreateDir(#[source] StdIO::Error),
#[error("Failed to write file")]
#[diagnostic(code(docs_md::io::write))]
FileWrite(#[source] StdIO::Error),
#[error("Item not found in index: {0}")]
#[diagnostic(code(docs_md::parse::item_not_found))]
ItemNotFound(String),
#[error("Invalid directory: {0}")]
#[diagnostic(
code(docs_md::io::dir),
help("Check that the directory exists and is readable")
)]
InvalidDirectory(String),
#[error("No rustdoc JSON files found in directory: {0}")]
#[diagnostic(
code(docs_md::parse::no_json),
help(
"Run `RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc` to generate JSON files"
)
)]
NoJsonFiles(PathBuf),
#[error("Duplicate crate name: {0}")]
#[diagnostic(
code(docs_md::parse::duplicate_crate),
help("Remove duplicate JSON files or rename crates")
)]
DuplicateCrate(String),
#[error("Could not determine crate name from JSON file: {0}")]
#[diagnostic(
code(docs_md::parse::no_crate_name),
help("Ensure the file is valid rustdoc JSON with a root module item")
)]
NoCrateName(PathBuf),
#[error("Invalid progress bar template")]
#[diagnostic(
code(docs_md::ui::progress_template),
help("Check the progress bar template syntax")
)]
ProgressBarTemplate(#[source] indicatif::style::TemplateError),
#[cfg(feature = "source-parsing")]
#[error("Source locator error: {0}")]
#[diagnostic(
code(docs_md::source::locator),
help("Ensure the crate is a dependency and has been downloaded (cargo fetch)")
)]
SourceLocator(String),
#[cfg(feature = "source-parsing")]
#[error("Source parser error: {0}")]
#[diagnostic(
code(docs_md::source::parser),
help("Check that the source files contain valid Rust code")
)]
SourceParser(String),
#[cfg(feature = "source-parsing")]
#[error("Source collector error: {0}")]
#[diagnostic(
code(docs_md::source::collector),
help("Ensure cargo metadata is available and ~/.cargo/registry/src/ exists")
)]
SourceCollector(String),
}