use std::num::ParseIntError;
use std::str::ParseBoolError;
use thiserror::Error;
use crate::protocol::errors::TypeParseError;
use crate::protocol::errors::{InvalidValueParseError, UnitsError, ValueError};
use crate::protocol::MavType;
#[derive(Debug, Error)]
pub enum XmlInspectionError {
#[error("dialects `{first}`, `{second}` have the same canonical name: `{canonical}`")]
NamingCollision {
first: String,
second: String,
canonical: String,
},
#[error("invalid path")]
InvalidPath,
}
#[derive(Clone, Debug, Error)]
pub enum XmlParseError {
#[error("incorrect tags order: tag `{inner}` appears inside tag {outer:?}")]
TagsNotInOrder {
outer: Option<String>,
inner: String,
},
#[error("incorrect closing tag: opened with `{opened_with:?}` but closed with {closed_with}")]
UnexpectedClosingTag {
opened_with: Option<String>,
closed_with: String,
},
#[error("impossible to parse dialect version: {0:?}")]
VersionParseFailed(ParseIntError),
#[error("impossible to parse dialect ID: {0:?}")]
DialectIdParseFailed(ParseIntError),
#[error("found a `<entry>` tag outside a `<enum>` tag")]
EnumEntryWithoutEnum,
#[error("impossible to parse enum `{enum_name:?}` entry `{entry_name:?}` value '{value:?}': {error:?}"
)]
EnumEntryValueParseFailed {
enum_name: String,
entry_name: String,
value: String,
error: ParseIntError,
},
#[error("found a `<param>` tag outside a `<enum>` tag")]
MavCmdParamWithoutEnumEntry,
#[error("invalid `hasLocation` field value: {0:?}")]
EnumEntryMavCmdFlagsInvalidHasLocation(ParseBoolError),
#[error("invalid `isDestination` field value in enum entry: {0:?}")]
EnumEntryMavCmdFlagsInvalidIsDestination(ParseBoolError),
#[error("invalid `missionOnly` field value in enum entry: {0:?}")]
EnumEntryMavCmdFlagsInvalidMissionOnly(ParseBoolError),
#[error("invalid `index` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidIndex(ParseIntError),
#[error("invalid `decimalPlaces` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidDecimalPlaces(ParseIntError),
#[error("invalid `increment` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidIncrement(ValueError),
#[error("invalid `minValue` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidMinValue(ValueError),
#[error("invalid `maxValue` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidMaxValue(ValueError),
#[error("invalid `reserved` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidReserved(ParseBoolError),
#[error("invalid `default` field value in enum entry param: {0:?}")]
EnumEntryMavCmdParamInvalidDefaultValue(ValueError),
#[error("invalid message ID: {0:?}")]
IncorrectMessageId(ParseIntError),
#[error("invalid message field type: {0:?}")]
IncorrectMessageFieldType(TypeParseError),
#[error("invalid message field `instance` field: {0:?}")]
IncorrectMessageFieldInstance(ParseBoolError),
#[error("invalid message field `default` field: {0:?}")]
IncorrectMessageFieldDefaultValue(ValueError),
#[error("invalid deprecated since date format: {0}")]
DeprecatedSinceDateIncorrectFormat(String),
#[error("invalid deprecated since year: {0}")]
DeprecatedSinceIncorrectYear(ParseIntError),
#[error("invalid deprecated since month: {0}")]
DeprecatedSinceIncorrectMonth(ParseIntError),
#[error("invalid value")]
IncorrectInvalidValue(InvalidValueParseError),
#[error("invalid units: {0:?}")]
IncorrectUnits(UnitsError),
#[error("found `<field>` tag outside of `<message>` tag")]
MessageFieldWithoutMessage,
#[error("found `<extensions>` tag outside of `<message>` tag")]
MessageExtensionsWithoutMessage,
#[error("found `<description>` tag outside of any appropriate tag")]
DescriptionWithoutSubject,
#[error("found `<deprecated>` tag outside of any appropriate tag")]
DeprecationWithoutSubject,
#[error("found `<wip>` tag outside of any appropriate tag")]
WipWithoutSubject,
#[error(
"message field `{field_name}` type `{field_type:?}` is too small \
to contain enum `{enum_name}` of type {enum_type:?}"
)]
MessageFieldISTooSmallForEnum {
enum_name: String,
enum_type: MavType,
field_name: String,
field_type: MavType,
},
#[error("error: {0}")]
Other(String),
}