selectors/
error.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use nom::error::ErrorKind;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum Error {
10    #[error("Static selector directories are expected to be flat")]
11    NonFlatDirectory,
12
13    #[error(transparent)]
14    Parse(#[from] ParseError),
15
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18
19    #[error("Selector arguments must be structured or raw")]
20    InvalidSelectorArgument,
21
22    #[error("Property selectors must have non-empty node_path vector")]
23    EmptyPropertySelectorNodePath,
24
25    #[error("TreeSelector only supports property and subtree selection.")]
26    InvalidTreeSelector,
27
28    #[error("Recursive wildcards aren't allowed in this position")]
29    RecursiveWildcardNotAllowed,
30
31    #[error("Selecter fails verification due to unmatched escape character")]
32    UnmatchedEscapeCharacter,
33
34    #[error(transparent)]
35    Validation(#[from] ValidationError),
36}
37
38#[derive(Debug, Error)]
39pub enum ParseError {
40    #[error("Failed to parse the input. Failed at: {0:?} with: {1:?}")]
41    Fast(String, ErrorKind),
42
43    #[error("Failed to parse the input. Error: {0}")]
44    Verbose(String),
45
46    #[error(transparent)]
47    Validation(#[from] ValidationError),
48}
49
50#[derive(Debug, Error)]
51pub enum ValidationError {
52    #[error("Component selectors require at least one segment")]
53    EmptyComponentSelector,
54
55    #[error("Subtree selectors must have non-empty node_path vector")]
56    EmptySubtreeSelector,
57
58    #[error("String selectors must be string patterns or exact matches")]
59    InvalidStringSelector,
60
61    #[error("String pattern '{0}' failed verification. Errors: {1:?}")]
62    InvalidStringPattern(String, Vec<StringPatternError>),
63
64    #[error("Selectors require a tree selector")]
65    MissingTreeSelector,
66
67    #[error("Selectors require a component selector")]
68    MissingComponentSelector,
69
70    #[error("String patterns cannot be empty.")]
71    EmptyStringPattern,
72}
73
74#[derive(Debug)]
75pub enum StringPatternError {
76    UnescapedGlob,
77    UnescapedColon,
78    UnescapedForwardSlash,
79}