Coverage Report

Created: 2025-02-21 07:11

/rust/registry/src/index.crates.io-6f17d22bba15001f/revision-0.10.0/src/error.rs
Line
Count
Source (jump to first uncovered line)
1
use std::{io, str::Utf8Error};
2
3
/// An error which occurs when revisioned serialization / deserialization fails.
4
#[derive(Debug)]
5
pub enum Error {
6
  /// An IO error occured.
7
  Io(io::Error),
8
  /// Tried to deserialize a boolean value with an invalid byte value.
9
  InvalidBoolValue(u8),
10
  /// Deserialization encountered integer encoding which is not suported.
11
  InvalidIntegerEncoding,
12
  /// Deserialization encountered an integer with a value which did not fit the target type..
13
  IntegerOverflow,
14
  /// Path contains invalid utf-8 characters
15
  InvalidPath,
16
  /// Invalid character encoding
17
  InvalidCharEncoding,
18
  /// Error parsing a string
19
  Utf8Error(Utf8Error),
20
  /// Failed to serialize character.
21
  Serialize(String),
22
  /// Generic deserialization error.
23
  Deserialize(String),
24
  /// Semantic translation/validation error.
25
  Conversion(String),
26
}
27
28
impl std::error::Error for Error {
29
0
  fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30
0
    match self {
31
0
      Error::Io(ref x) => Some(x),
32
0
      Error::Utf8Error(ref x) => Some(x),
33
0
      _ => None,
34
    }
35
0
  }
36
}
37
38
impl std::fmt::Display for Error {
39
0
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
40
0
    match self {
41
0
      Self::Io(e) => write!(f, "An IO error occured: {}", e),
42
      Self::InvalidBoolValue(_) => {
43
0
        write!(f, "Tried to deserialize a boolean value with an invalid byte value.")
44
      }
45
      Self::InvalidIntegerEncoding => {
46
0
        write!(f, "Encountered invalid integer encoding.")
47
      }
48
      Self::IntegerOverflow => {
49
0
        write!(f, "Encountered integer which doesn't fit the target integer type during deserialization.")
50
      }
51
      Self::InvalidPath => {
52
0
        write!(f, "Path contained invalid UTF-8 characters.")
53
      }
54
      Self::InvalidCharEncoding => {
55
0
        write!(f, "Invalid character encoding.")
56
      }
57
0
      Self::Utf8Error(x) => {
58
0
        write!(f, "Invalid UTF-8 characters in string: {x}")
59
      }
60
0
      Self::Serialize(e) => write!(f, "A serialization error occured: {}", e),
61
0
      Self::Deserialize(e) => write!(f, "A deserialization error occured: {}", e),
62
0
      Self::Conversion(e) => write!(f, "A user generated conversion error occured: {}", e),
63
    }
64
0
  }
65
}