svg_path_cst/
errors.rs

1use crate::alloc::string::String;
2use snafu::prelude::*;
3
4/// Syntax errors that can occur when parsing an SVG path
5///
6/// These errors try to be exhaustive.
7#[derive(Debug, PartialEq, Snafu, Clone)]
8pub enum SyntaxError {
9    /// The first command in a path is not moveto.
10    #[snafu(display(
11        "Invalid SVG path command '{character}' at index {index}, expected 'M' or 'm'"
12    ))]
13    ExpectedMovetoCommand {
14        /// Command letter found
15        character: char,
16        /// Index of the command in the path
17        index: usize,
18    },
19
20    /// Invalid number found in path.
21    #[snafu(display("Invalid number '{number}' at index {start}"))]
22    InvalidNumber {
23        /// Number found
24        number: String,
25        /// Index of the number in the path
26        start: usize,
27        /// Index of the end of the number in the path
28        end: usize,
29    },
30
31    /// Invalid character found in path.
32    #[snafu(display(
33        "Invalid character '{character}' at index {index}, expected {expected}"
34    ))]
35    InvalidCharacter {
36        /// Character found
37        character: char,
38        /// Index of the character in the path
39        index: usize,
40        /// Expected character
41        expected: &'static str,
42    },
43
44    /// Invalid path ending.
45    #[snafu(display("Unexpected SVG path end at index {index}, expected {expected}"))]
46    UnexpectedEnding {
47        /// Index of the end of the path
48        index: usize,
49        /// Expected token
50        expected: &'static str,
51    },
52
53    /// Invalid SVG quaractic arc command flag argument.
54    #[snafu(display("Invalid SVG path elliptical arc flag at index {index}. Expected 0 or 1 but found '{character}'"))]
55    InvalidArcFlag {
56        /// Command letter
57        command: char,
58        /// Character found instead of valid arc flag (0 or 1)
59        character: char,
60        /// Index of the command in the path
61        index: usize,
62    },
63
64    /// Invalid SVG quaractic arc command radius argument.
65    #[snafu(display("Invalid SVG path elliptical arc command '{command}' radius at index {start}. Expected positive number but found '{value}'"))]
66    InvalidArcRadius {
67        /// Command letter
68        command: char,
69        /// Index of the command in the path
70        start: usize,
71        /// Index of the end of the number in the path
72        end: usize,
73        /// Value found
74        value: f64,
75    },
76}