pub struct ShapeError {
pub path: String,
pub message: String,
}Expand description
A failed ConfigShape::from_value, carrying where.
The host validates the tree against the schema before a guest ever sees it,
so in practice a guest’s from_value fails only on a value the host could
not have checked — a type the schema calls a string but the guest wants to
interpret further (an enum spelled as a string, a path, a duration). Those
are exactly the cases where a path matters, so it is carried rather than
dropped.
Display renders path: message, or just message at the root.
§Examples
use lattice_plugin_sdk::shape::{ConfigShape, Value};
let v = Value::List(vec![Value::Int(1), Value::Str("two".into())]);
let err = <Vec<i64>>::from_value(&v).unwrap_err();
assert_eq!(err.path, "[1]");
assert_eq!(err.to_string(), "[1]: expected integer, got string");Fields§
§path: StringWhere the failure is, outermost segment first: field names joined with
., list indices as [i] with no dot before them
(templates[2].target.file). Empty when the root value itself failed.
message: StringWhat went wrong at that location, e.g. expected integer, got string or
required field is missing.
Implementations§
Source§impl ShapeError
impl ShapeError
Sourcepub fn under(self, segment: &str) -> Self
pub fn under(self, segment: &str) -> Self
Prepend a segment as this error unwinds back up the walk. The derive calls it per field, so a leaf failure arrives at the top with the full path assembled and no field having had to know where it lives.
A . separator is inserted unless the existing path begins with an
index segment ([), so indices attach directly to their list.
§Examples
use lattice_plugin_sdk::shape::ShapeError;
// Segments are discovered inside-out, so they are prepended.
let e = ShapeError::new("boom").under("file").under("[0]").under("targets");
assert_eq!(e.path, "targets[0].file");Trait Implementations§
Source§impl Clone for ShapeError
impl Clone for ShapeError
Source§fn clone(&self) -> ShapeError
fn clone(&self) -> ShapeError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShapeError
impl Debug for ShapeError
Source§impl Display for ShapeError
impl Display for ShapeError
impl Eq for ShapeError
Source§impl Error for ShapeError
impl Error for ShapeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()