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.
45use nom::error::ErrorKind;
6use thiserror::Error;
78#[derive(Debug, Error)]
9pub enum Error {
10#[error("Static selector directories are expected to be flat")]
11NonFlatDirectory,
1213#[error(transparent)]
14Parse(#[from] ParseError),
1516#[error(transparent)]
17Io(#[from] std::io::Error),
1819#[error("Selector arguments must be structured or raw")]
20InvalidSelectorArgument,
2122#[error("Property selectors must have non-empty node_path vector")]
23EmptyPropertySelectorNodePath,
2425#[error("TreeSelector only supports property and subtree selection.")]
26InvalidTreeSelector,
2728#[error("Recursive wildcards aren't allowed in this position")]
29RecursiveWildcardNotAllowed,
3031#[error("Selecter fails verification due to unmatched escape character")]
32UnmatchedEscapeCharacter,
3334#[error(transparent)]
35Validation(#[from] ValidationError),
36}
3738#[derive(Debug, Error)]
39pub enum ParseError {
40#[error("Failed to parse the input. Failed at: {0:?} with: {1:?}")]
41Fast(String, ErrorKind),
4243#[error("Failed to parse the input. Error: {0}")]
44Verbose(String),
4546#[error(transparent)]
47Validation(#[from] ValidationError),
48}
4950#[derive(Debug, Error)]
51pub enum ValidationError {
52#[error("Component selectors require at least one segment")]
53EmptyComponentSelector,
5455#[error("Subtree selectors must have non-empty node_path vector")]
56EmptySubtreeSelector,
5758#[error("String selectors must be string patterns or exact matches")]
59InvalidStringSelector,
6061#[error("String pattern '{0}' failed verification. Errors: {1:?}")]
62InvalidStringPattern(String, Vec<StringPatternError>),
6364#[error("Selectors require a tree selector")]
65MissingTreeSelector,
6667#[error("Selectors require a component selector")]
68MissingComponentSelector,
6970#[error("String patterns cannot be empty.")]
71EmptyStringPattern,
72}
7374#[derive(Debug)]
75pub enum StringPatternError {
76 UnescapedGlob,
77 UnescapedColon,
78 UnescapedForwardSlash,
79}