mavinspect 0.1.0-alpha2

MAVInspect is a CLI tool and a library to parse and inspect MAVLink protocol XML definitions
Documentation
use std::num::{ParseFloatError, ParseIntError};
use std::str::ParseBoolError;

use thiserror::Error;

use crate::protocol::errors::ParseError;
use crate::protocol::MessageFieldParsingError;

/// Errors which may happen during XML parsing
#[derive(Debug, Clone, Error)]
pub enum XmlParseError {
    /// XML tags appears in invalid order.
    #[error("incorrect tags order: tag `{after}` appears inside tag {before:?}")]
    InvalidTagsOrder {
        before: Option<String>,
        after: String,
    },
    /// Trying to close tag which was not immediately opened.
    #[error("incorrect closing tag: opened with `{opened_with:?}` but closed with {closed_with}")]
    InvalidClosingTag {
        opened_with: Option<String>,
        closed_with: String,
    },

    /// Impossible to parse dialect version.
    #[error("impossible to parse dialect version: {0:?}")]
    VersionParseFailed(ParseIntError),
    /// Impossible to parse dialect ID.
    #[error("impossible to parse dialect ID: {0:?}")]
    DialectIdParseFailed(ParseIntError),

    /// Found enum entry `<entry>` outside of enum definition `<enum>`.
    #[error("found `<entry>` tag outside of `<enum>` tag")]
    EnumEntryWithoutEnum,
    /// Impossible to parse enum entry value.
    #[error("impossible to parse enum entry value: {0:?}")]
    EnumEntryValueParseFailed(ParseIntError),

    /// Found `<param>` tag outside of `<enum>` tag.
    #[error("found `<param>` tag outside of `<enum>` tag")]
    MavCmdParamWithoutEnumEntry,
    /// Invalid `hasLocation` field value in enum entry.
    #[error("invalid `hasLocation` field value: {0:?}")]
    EnumEntryMavCmdFlagsInvalidHasLocation(ParseBoolError),
    /// Invalid `isDestination` field value in enum entry.
    #[error("invalid `isDestination` field value in enum entry: {0:?}")]
    EnumEntryMavCmdFlagsInvalidIsDestination(ParseBoolError),
    /// Invalid `missionOnly` field value in enum entry.
    #[error("invalid `missionOnly` field value in enum entry: {0:?}")]
    EnumEntryMavCmdFlagsInvalidMissionOnly(ParseBoolError),
    /// Invalid `index` field value in enum entry param.
    #[error("invalid `index` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidIndex(ParseIntError),
    /// Invalid `decimalPlaces` field value in enum entry param.
    #[error("invalid `decimalPlaces` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidDecimalPlaces(ParseIntError),
    /// Invalid `increment` field value in enum entry param.
    #[error("invalid `increment` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidIncrement(ParseError),
    /// Invalid `minValue` field value in enum entry param.
    #[error("invalid `minValue` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidMinValue(ParseError),
    /// Invalid `maxValue` field value in enum entry param.
    #[error("invalid `maxValue` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidMaxValue(ParseError),
    /// Invalid `reserved` field value in enum entry param.
    #[error("invalid `reserved` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidReserved(ParseBoolError),
    /// Invalid `default` field value in enum entry param.
    #[error("invalid `default` field value in enum entry param: {0:?}")]
    EnumEntryMavCmdParamInvalidDefaultValue(ParseError),

    /// Invalid message ID.
    #[error("invalid message ID: {0:?}")]
    InvalidMessageId(ParseIntError),

    /// Impossible to parse message field
    #[error("invalid message field: {0:?}")]
    InvalidMessageField(MessageFieldParsingError),
    /// Invalid message field `instance` field.
    #[error("invalid message field `instance` field: {0:?}")]
    InvalidMessageFieldInstance(ParseBoolError),

    /// Invalid deprecated since date format.
    #[error("invalid deprecated since date format: {0}")]
    InvalidDeprecatedSinceDateFormat(String),
    /// Invalid deprecated since year or month.
    #[error("invalid deprecated since year: {0}")]
    InvalidDeprecatedSinceYear(ParseIntError),
    /// Invalid deprecated since year or month.
    #[error("invalid deprecated since month: {0}")]
    InvalidDeprecatedSinceMonth(ParseIntError),

    /// Invalid value
    #[error("invalid value")]
    InvalidValue(ParseError),
    /// Value is specified by incorrect integer representation.
    #[error("value is specified by incorrect integer representation: {0:?}")]
    InvalidIntValue(ParseIntError),
    /// Value is specified by incorrect floating point representation.
    #[error("value is specified by incorrect floating point representation: {0:?}")]
    InvalidFloatValue(ParseFloatError),

    /// Invalid units
    #[error("invalid units: {0:?}")]
    UnitsError(ParseError),

    /// Found message field `<field>` tag outside of message definition `<message>`.
    #[error("found `<field>` tag outside of `<message>` tag")]
    MessageFieldWithoutMessage,
    /// Found `<extensions>` tag outside of message definition `<message>`.
    #[error("found `<extensions>` tag outside of `<message>` tag")]
    MessageExtensionsWithoutMessage,

    /// Found `<description>` tag outside of any appropriate tag.
    #[error("found `<description>` tag outside of any appropriate tag")]
    DescriptionWithoutSubject,
    /// Found `<deprecated>` tag outside of any appropriate tag.
    #[error("found `<deprecated>` tag outside of any appropriate tag")]
    DeprecationWithoutSubject,
    /// Found `<wip>` tag outside of any appropriate tag.
    #[error("found `<wip>` tag outside of any appropriate tag")]
    WipWithoutSubject,
}