pub struct Error {
pub kind: ErrorKind,
pub context: Option<String>,
}Expand description
Error type for Automorph operations.
This error is returned when synchronization fails, typically due to:
- Type mismatches between the Rust struct and Automerge document
- Missing required fields
- Invalid data in the Automerge document
§Example
use automorph::{Automorph, Error};
use automerge::{AutoCommit, ROOT};
let doc = AutoCommit::new();
// Trying to read a String from an empty document fails
let result = String::load(&doc, &ROOT, "missing");
assert!(result.is_err());Fields§
§kind: ErrorKindThe kind of error that occurred.
context: Option<String>Additional context about where the error occurred.
Implementations§
Source§impl Error
impl Error
Sourcepub fn type_mismatch(expected: &'static str, found: Option<String>) -> Self
pub fn type_mismatch(expected: &'static str, found: Option<String>) -> Self
Creates a new type mismatch error.
Sourcepub fn missing_field(field: impl Into<String>) -> Self
pub fn missing_field(field: impl Into<String>) -> Self
Creates a new missing field error.
Sourcepub fn missing_value() -> Self
pub fn missing_value() -> Self
Creates a new missing value error.
Sourcepub fn invalid_value(reason: impl Into<String>) -> Self
pub fn invalid_value(reason: impl Into<String>) -> Self
Creates a new invalid value error.
Sourcepub fn expected_type(expected: &'static str, type_name: &str) -> Self
pub fn expected_type(expected: &'static str, type_name: &str) -> Self
Creates a type mismatch error for expected struct type.
Sourcepub fn unknown_field(field: impl Into<String>) -> Self
pub fn unknown_field(field: impl Into<String>) -> Self
Creates an unknown field error.
Sourcepub fn with_context(self, context: impl Into<String>) -> Self
pub fn with_context(self, context: impl Into<String>) -> Self
Adds context to this error.
Sourcepub fn with_field(self, field: impl Into<String>) -> Self
pub fn with_field(self, field: impl Into<String>) -> Self
Prepends a field name to the existing context path.
This is useful for building up paths like “person.address.city” when errors bubble up through nested structures.
§Example
use automorph::Error;
let err = Error::missing_value()
.with_field("city")
.with_field("address")
.with_field("person");
// Error message will show: "at person.address.city"Sourcepub fn with_index(self, index: usize) -> Self
pub fn with_index(self, index: usize) -> Self
Prepends an array index to the existing context path.
§Example
use automorph::Error;
let err = Error::missing_value()
.with_index(2)
.with_field("items");
// Error message will show: "at items[2]"Sourcepub fn is_missing_value(&self) -> bool
pub fn is_missing_value(&self) -> bool
Returns true if this error is a missing value error.
Sourcepub fn is_missing_field(&self) -> bool
pub fn is_missing_field(&self) -> bool
Returns true if this error is a missing field error.
Sourcepub fn is_type_mismatch(&self) -> bool
pub fn is_type_mismatch(&self) -> bool
Returns true if this error is a type mismatch error.
Sourcepub fn is_unknown_field(&self) -> bool
pub fn is_unknown_field(&self) -> bool
Returns true if this error is an unknown field error.
Sourcepub fn is_invalid_value(&self) -> bool
pub fn is_invalid_value(&self) -> bool
Returns true if this error is an invalid value error.
Sourcepub fn is_automerge(&self) -> bool
pub fn is_automerge(&self) -> bool
Returns true if this error is an Automerge error.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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
Source§impl From<AutomergeError> for Error
impl From<AutomergeError> for Error
Source§fn from(err: AutomergeError) -> Self
fn from(err: AutomergeError) -> Self
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more