ElyPDF: an OS permission error shows as an error, never a missing text key (P-01); component library f834f55
This commit is contained in:
17 files changed
+90
-25
No files matched your search
@@ -293,10 +293,30 @@ impl Drop for Worker {
|
||||
}
|
||||
}
|
||||
|
||||
/// A permission refusal is `PermissionDenied`, named by what it needs.
|
||||
/// A request the document's permissions refused, by what it needs.
|
||||
#[derive(Debug)]
|
||||
pub struct Refused(pub &'static str);
|
||||
|
||||
impl std::fmt::Display for Refused {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}{}", crate::proto::may::REFUSED, self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Refused {}
|
||||
|
||||
/// What a permission refusal needs; none for other errors.
|
||||
pub fn refused(error: &io::Error) -> Option<&'static str> {
|
||||
error.get_ref()?.downcast_ref::<Refused>().map(|refused| refused.0)
|
||||
}
|
||||
|
||||
/// A worker error; a refusal names a permission it knows.
|
||||
fn refusal(text: String) -> io::Error {
|
||||
match text.strip_prefix(crate::proto::may::REFUSED) {
|
||||
Some(needed) => io::Error::new(io::ErrorKind::PermissionDenied, needed.to_string()),
|
||||
let named = text
|
||||
.strip_prefix(crate::proto::may::REFUSED)
|
||||
.and_then(|needed| crate::proto::may::NAMES.iter().find(|(_, name)| *name == needed));
|
||||
match named {
|
||||
Some((_, name)) => io::Error::other(Refused(name)),
|
||||
None => io::Error::other(text),
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ pub mod proto;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod sample;
|
||||
|
||||
pub use client::{Doc, Opened, Tile, Worker, is_stale};
|
||||
pub use client::{Doc, Opened, Refused, Tile, Worker, is_stale, refused};
|
||||
pub use content::{Drawn, TextBlock, Writing, Wrote};
|
||||
pub use ocr::{OcrLine, tessdata};
|
||||
pub use output::Optimizing;
|
||||
|
||||
Reference in new issue
Block a user