usecrate::libyaml::{emitter, error as libyaml}; usecrate::path::Path; use serde::{de, ser}; use std::error::Error as StdError; use std::fmt::{self, Debug, Display}; use std::io; use std::result; use std::string; use std::sync::Arc;
/// An error that happened serializing or deserializing YAML data. pubstruct Error(Box<ErrorImpl>);
/// Alias for a `Result` with the error type `serde_yaml::Error`. pubtype Result<T> = result::Result<T, Error>;
/// The input location that an error occured. #[derive(Debug)] pubstruct Location {
index: usize,
line: usize,
column: usize,
}
impl Location { /// The byte index of the error pubfn index(&self) -> usize { self.index
}
/// The line of the error pubfn line(&self) -> usize { self.line
}
/// The column of the error pubfn column(&self) -> usize { self.column
}
// This is to keep decoupled with the yaml crate #[doc(hidden)] fn from_mark(mark: libyaml::Mark) -> Self {
Location {
index: mark.index() as usize, // `line` and `column` returned from libyaml are 0-indexed but all error messages add +1 to this value
line: mark.line() as usize + 1,
column: mark.column() as usize + 1,
}
}
}
impl Error { /// Returns the Location from the error if one exists. /// /// Not all types of errors have a location so this can return `None`. /// /// # Examples /// /// ``` /// # use serde_yaml::{Value, Error}; /// # /// // The `@` character as the first character makes this invalid yaml /// let invalid_yaml: Result<Value, Error> = serde_yaml::from_str("@invalid_yaml"); /// /// let location = invalid_yaml.unwrap_err().location().unwrap(); /// /// assert_eq!(location.line(), 1); /// assert_eq!(location.column(), 1); /// ``` pubfn location(&self) -> Option<Location> { self.0.location()
}
}
// Remove two layers of verbosity from the debug representation. Humans often // end up seeing this representation because it is what unwrap() shows. impl Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.debug(f)
}
}
fn message_no_mark(&self, f: &mut fmt::Formatter) -> fmt::Result { matchself {
ErrorImpl::Message(msg, None) => f.write_str(msg),
ErrorImpl::Message(msg, Some(Pos { mark: _, path })) => { if path != "." {
write!(f, "{}: ", path)?;
}
f.write_str(msg)
}
ErrorImpl::Libyaml(_) => unreachable!(),
ErrorImpl::Io(err) => Display::fmt(err, f),
ErrorImpl::FromUtf8(err) => Display::fmt(err, f),
ErrorImpl::EndOfStream => f.write_str("EOF while parsing a value"),
ErrorImpl::MoreThanOneDocument => f.write_str( "deserializing from YAML containing more than one document is not supported",
),
ErrorImpl::RecursionLimitExceeded(_mark) => f.write_str("recursion limit exceeded"),
ErrorImpl::RepetitionLimitExceeded => f.write_str("repetition limit exceeded"),
ErrorImpl::BytesUnsupported => {
f.write_str("serialization and deserialization of bytes in YAML is not implemented")
}
ErrorImpl::UnknownAnchor(_mark) => f.write_str("unknown anchor"),
ErrorImpl::SerializeNestedEnum => {
f.write_str("serializing nested enums in YAML is not supported yet")
}
ErrorImpl::ScalarInMerge => {
f.write_str("expected a mapping or list of mappings for merging, but found scalar")
}
ErrorImpl::TaggedInMerge => f.write_str("unexpected tagged value in merge"),
ErrorImpl::ScalarInMergeElement => {
f.write_str("expected a mapping for merging, but found scalar")
}
ErrorImpl::SequenceInMergeElement => {
f.write_str("expected a mapping for merging, but found sequence")
}
ErrorImpl::EmptyTag => f.write_str("empty YAML tag is not allowed"),
ErrorImpl::FailedToParseNumber => f.write_str("failed to parse YAML number"),
ErrorImpl::Shared(_) => unreachable!(),
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.