keyvalues_parser/
error.rs

1//! All error information for parsing and rendering
2
3// TODO: is this still true?
4// This library supports an MSRV of 1.42.0 which is before the addition of
5// clippy::nonstandard_macro_braces. This lint is used within `thiserror` which in turn gets
6// expanded out here causing clippy to throw out an unknown lint warning which fails CI. Until this
7// gets resolved upstream I'm going to allow `unknown_clippy_lints` as a stopgap. Relevant:
8// https://github.com/dtolnay/thiserror/issues/140
9// https://github.com/dtolnay/thiserror/issues/141
10#![allow(renamed_and_removed_lints)]
11#![allow(clippy::unknown_clippy_lints)]
12
13use thiserror::Error as ThisError;
14
15use crate::text::parse::{EscapedPestError, RawPestError};
16
17/// Just a type alias for `Result` with a [`Error`]
18pub type Result<T> = std::result::Result<T, Error>;
19
20// TODO: Swap out the `EscapedParseError` and `RawParseError` for an opaque `Error::Parse` variant
21// that handles displaying the error
22// TODO: should this whole thing be overhauled
23// TODO: Sort out new MSRV
24
25/// All possible errors when parsing or rendering VDF text
26///
27/// Currently the two variants are parse errors which currently only occurs when `pest` encounters
28#[derive(ThisError, Clone, Debug, PartialEq, Eq)]
29pub enum Error {
30    #[error("Failed parsing input Error: {0}")]
31    EscapedParseError(#[from] EscapedPestError),
32    #[error("Failed parsing input Error: {0}")]
33    RawParseError(#[from] RawPestError),
34    #[error("Failed rendering input Error: {0}")]
35    RenderError(#[from] std::fmt::Error),
36    #[error("Encountered invalid character in raw string: {invalid_char:?}")]
37    RawRenderError { invalid_char: char },
38}