1use pest::error::Error as PestError;
4use std::{io, num};
5use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum VmfError {
10 #[error("IO error: {0}")]
12 Io(#[from] io::Error),
13
14 #[error("VMF parse error: {0}")]
16 Parse(#[from] Box<PestError<crate::parser::Rule>>),
17
18 #[error("Invalid VMF format: {0}")]
20 InvalidFormat(String),
21
22 #[error("Integer parse error for key '{key}': {source}")]
24 ParseInt {
25 key: String,
26 #[source]
27 source: num::ParseIntError,
28 },
29
30 #[error("Float parse error for key '{key}': {source}")]
32 ParseFloat {
33 key: String,
34 #[source]
35 source: num::ParseFloatError,
36 },
37}
38
39pub type VmfResult<T> = Result<T, VmfError>;
41
42impl From<(std::num::ParseIntError, String)> for VmfError {
43 fn from(err: (std::num::ParseIntError, String)) -> Self {
44 VmfError::ParseInt {
45 source: err.0,
46 key: err.1,
47 }
48 }
49}
50
51impl From<(std::num::ParseFloatError, String)> for VmfError {
52 fn from(err: (std::num::ParseFloatError, String)) -> Self {
53 VmfError::ParseFloat {
54 source: err.0,
55 key: err.1,
56 }
57 }
58}