slop_rs/error.rs
1//! Defines [slop_rs](crate)'s error types.
2
3use std::io;
4
5use thiserror::Error;
6
7/// Alias of [Result] where [Err] holds a [SlopError].
8pub type SlopResult<T> = Result<T, SlopError>;
9
10/// The possible errors returned by the SLOP API.
11///
12/// See also: [SlopResult]
13#[derive(Debug, Error)]
14pub enum SlopError {
15 /// While parsing, the line was not a valid string KV or list KV starter.
16 ///
17 /// Holds the 0-based index and contents if the line in question.
18 /// The index is written as 1-based when displayed.
19 #[error("(in line {}) `{1}` is not a valid kv", .0 + 1)]
20 InvalidLine(usize, String),
21
22 /// While parsing, the list KV was never closed.
23 ///
24 /// Holds the 0-based index and contents of the line that starts the KV.
25 /// The index is written as 1-based when displayed.
26 #[error("(in line {}) `{1}` is not closed", .0 + 1)]
27 UnclosedList(usize, String),
28
29 /// Returned during [Slop::insert](crate::Slop::insert) if the key contains
30 /// `=` or ends in `{`.
31 #[error("the key `{0}` contains invalid characters")]
32 InvalidKey(String),
33
34 /// Wrapper for [io::Error]s.
35 #[error("io error: {0}")]
36 Io(#[from] io::Error),
37}