1use crate::olean::SUPPORTED;
2use std::{
3 fmt::Display,
4 io,
5 path::{Path, PathBuf},
6};
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[error(transparent)]
13 Io(#[from] io::Error),
14 #[error("module {0} not found on LEAN_PATH")]
15 ModuleNotFound(String),
16 #[error("not an olean file")]
17 NotOlean,
18 #[error("unsupported olean format {0}")]
19 Format(u8),
20 #[error(
21 "built by Lean {0}, but only 4.{lo} to 4.{hi} are supported",
22 lo = SUPPORTED.start(),
23 hi = SUPPORTED.end()
24 )]
25 UnsupportedLean(String),
26 #[error("{0}")]
28 Corrupt(String),
29 #[error("{}: {source}", path.display())]
30 File { path: PathBuf, source: Box<Self> },
31 #[error(transparent)]
32 Threads(#[from] rayon::ThreadPoolBuildError),
33}
34
35pub type Result<T, E = Error> = std::result::Result<T, E>;
36
37pub(crate) fn corrupt(msg: impl Display) -> Error {
38 Error::Corrupt(msg.to_string())
39}
40
41pub(crate) fn at(path: &Path) -> impl FnOnce(Error) -> Error + '_ {
42 move |e| Error::File {
43 path: path.to_owned(),
44 source: Box::new(e),
45 }
46}