2019-09-10 19:55:32 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2019-09-12 15:39:25 +00:00
|
|
|
InvalidPath(crate::store::StorePath),
|
|
|
|
BadStorePath(std::path::PathBuf),
|
|
|
|
BadNarInfo,
|
2019-09-10 23:15:20 +00:00
|
|
|
IOError(std::io::Error),
|
2019-09-12 15:39:25 +00:00
|
|
|
HttpError(reqwest::Error),
|
2019-09-10 19:55:32 +00:00
|
|
|
Misc(String),
|
2019-09-10 23:15:20 +00:00
|
|
|
Foreign(CppException),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
|
|
fn from(err: std::io::Error) -> Self {
|
|
|
|
Error::IOError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 15:39:25 +00:00
|
|
|
impl From<reqwest::Error> for Error {
|
|
|
|
fn from(err: reqwest::Error) -> Self {
|
|
|
|
Error::HttpError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:15:20 +00:00
|
|
|
impl From<Error> for CppException {
|
|
|
|
fn from(err: Error) -> Self {
|
|
|
|
match err {
|
2019-09-12 15:39:25 +00:00
|
|
|
Error::InvalidPath(_) => unsafe { make_error("invalid path") }, // FIXME
|
|
|
|
Error::BadNarInfo => unsafe { make_error(".narinfo file is corrupt") }, // FIXME
|
|
|
|
Error::BadStorePath(path) => unsafe {
|
|
|
|
make_error(&format!("path '{}' is not a store path", path.display()))
|
|
|
|
}, // FIXME
|
|
|
|
Error::IOError(err) => unsafe { make_error(&err.to_string()) },
|
|
|
|
Error::HttpError(err) => unsafe { make_error(&err.to_string()) },
|
2019-09-10 23:15:20 +00:00
|
|
|
Error::Foreign(ex) => ex,
|
|
|
|
Error::Misc(s) => unsafe { make_error(&s) },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CppException(*const libc::c_void); // == std::exception_ptr*
|
|
|
|
|
|
|
|
extern "C" {
|
2019-09-11 10:44:31 +00:00
|
|
|
#[allow(improper_ctypes)] // YOLO
|
2019-09-10 23:15:20 +00:00
|
|
|
fn make_error(s: &str) -> CppException;
|
2019-09-10 19:55:32 +00:00
|
|
|
}
|