use std::path::PathBuf;
use ironlab_ir::{IrError, ValidationReport};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error(
"cannot tell the figure format of {}: use the extension .fig for Protocol Buffers or .json (such as .fig.json) for JSON",
.0.display()
)]
UnsupportedFormat(PathBuf),
#[error(transparent)]
Ir(#[from] IrError),
#[error(transparent)]
Export(#[from] ironlab_viewer::ExportError),
#[error("viewer failed: {0}")]
Viewer(#[from] eframe::Error),
#[error("the figure is invalid: {}", summarise(.0))]
Invalid(ValidationReport),
}
fn summarise(report: &ValidationReport) -> String {
report
.errors
.iter()
.map(|issue| issue.message.as_str())
.collect::<Vec<_>>()
.join("; ")
}