Skip to main content

valve_keyvalue/
error.rs

1/*
2   Copyright 2026 Gerg0Vagyok
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17#[derive(Debug, PartialEq, Eq)]
18pub enum Error {
19	UndefinedError,
20	UnexpectedEndOfFile,
21	UnexpectedObjectAsKey{line: usize, col: usize},
22	UnexpectedEndOfObject{line: usize, col: usize},
23	MissingValue {line: usize, col: usize},
24	QuoteInNonEscapeSequencedString
25}
26
27impl std::fmt::Display for Error {
28	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29		match self {
30			Error::UndefinedError => write!(f, "Undefined error"),
31			Error::UnexpectedEndOfFile => write!(f, "Unexpected end of file"),
32			Error::UnexpectedObjectAsKey { line, col } => write!(f, "Unexpected object as key at {}:{}", line, col),
33			Error::UnexpectedEndOfObject { line, col } => write!(f, "Unexpected end of object at {}:{}", line, col),
34			Error::MissingValue { line, col } => write!(f, "Missing value at {}:{}", line, col),
35			Error::QuoteInNonEscapeSequencedString => write!(f, "Quote in non-escape sequenced string")
36		}
37	}
38}
39
40impl std::error::Error for Error {}
41
42pub type Result<T> = std::result::Result<T, Error>;