Skip to main content

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