[−][src]Struct figment::error::Error
An error that occured while producing data or extracting a configuration.
Constructing Errors
An Error
will generally be constructed indirectly via its implementations
of serde's de::Error
and ser::Error
, that is, as a result of
serialization or deserialization errors. When implementing Provider
,
however, it may be necessary to construct an Error
directly.
Broadly, there are two ways to construct an Error
:
-
Via an error message, since
Error
implsFrom<String>
:use figment::Error; Error::from("whoops, something went wrong!".to_string());
-
Via a
Kind
, sinceError
implsFrom<Kind>
:use figment::{error::{Error, Kind}, value::Value}; let value = Value::serialize(&100).unwrap(); if !value.as_str().is_some() { let kind = Kind::InvalidType(value.to_actual(), "string".into()); let error = Error::from(kind); }
As always, ?
can be used to automatically convert into an Error
using
the available From
implementations:
use std::fs::File; fn try_read() -> Result<(), figment::Error> { let x = File::open("/tmp/foo.boo").map_err(|e| e.to_string())?; Ok(()) }
Display
By default, Error
uses all of the available information about the error,
including the Metadata
, path
, and profile
to display a message that
resembles the following, where $
is error.
for some error: Error
:
$kind: `$metadata.interpolate($path)` in $($metadata.sources())*
Concretely, such an error may look like:
invalid type: found sequence, expected u16: `staging.port` in TOML file Config.toml
Iterator
An Error
may contain more than one error. To process all errors, iterator
over an Error
:
fn with_error(error: figment::Error) { for error in error { println!("error: {}", error); } }
Fields
profile: Option<Profile>
The profile that was selected when the error occured, if any.
metadata: Option<Metadata>
The metadata for the provider of the value that errored, if known.
path: Vec<String>
The path to the configuration key that errored, if known.
kind: Kind
The error kind.
Implementations
impl Error
[src]
pub fn missing(&self) -> bool
[src]
Returns true
if the error's kind is MissingField
.
Example
use figment::error::{Error, Kind}; let error = Error::from(Kind::MissingField("path".into())); assert!(error.missing());
pub fn with_path(self, path: &str) -> Self
[src]
Append the string path
to the error's path.
Example
use figment::Error; let error = Error::from("an error message".to_string()) .with_path("some_path");
Trait Implementations
impl Clone for Error
[src]
impl Debug for Error
[src]
impl Display for Error
[src]
impl Error for Error
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
1.30.0[src]
fn backtrace(&self) -> Option<&Backtrace>
[src]
fn description(&self) -> &str
1.0.0[src]
fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl Error for Error
[src]
impl Error for Error
[src]
fn custom<T: Display>(msg: T) -> Self
[src]
fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
[src]
fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self
[src]
fn invalid_length(len: usize, exp: &dyn Expected) -> Self
[src]
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self
[src]
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self
[src]
fn missing_field(field: &'static str) -> Self
[src]
fn duplicate_field(field: &'static str) -> Self
[src]
impl From<Kind> for Error
[src]
impl From<String> for Error
[src]
impl IntoIterator for Error
[src]
type Item = Error
The type of the elements being iterated over.
type IntoIter = IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl PartialEq<Error> for Error
[src]
impl StructuralPartialEq for Error
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,