diff --git a/src/error.rs b/src/error.rs index 27ab805..4429dd4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,7 @@ //! Various types of errors that `font-kit` can return. +use std::borrow::Cow; use std::convert::From; use std::error::Error; use std::io; @@ -91,18 +92,21 @@ impl From for GlyphLoadingError { } /// Reasons why a source might fail to look up a font or fonts. -#[derive(Clone, Copy, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug)] pub enum SelectionError { /// No font matching the given query was found. NotFound, /// The source was inaccessible because of an I/O or similar error. - CannotAccessSource, + CannotAccessSource { + /// Additional diagnostic information may include file name + reason: Option>, + }, } impl Error for SelectionError {} impl_display! { SelectionError, { NotFound => "no font found", - CannotAccessSource => "failed to access source", + CannotAccessSource { reason: ref maybe_cow } => maybe_cow.as_deref().unwrap_or("failed to access source") } } diff --git a/src/sources/core_text.rs b/src/sources/core_text.rs index c323eb6..e4b6292 100644 --- a/src/sources/core_text.rs +++ b/src/sources/core_text.rs @@ -230,13 +230,13 @@ fn create_handle_from_descriptor(descriptor: &CTFontDescriptor) -> Result Result Ok(Handle::from_memory(font_data, 0)), - Err(_) => Err(SelectionError::CannotAccessSource), + Err(e) => Err(SelectionError::CannotAccessSource { + reason: Some(format!("{:?} error on path {:?}", e, font_path).into()), + }), } }