• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Xevion / Pac-Man / 16896410642

12 Aug 2025 01:23AM UTC coverage: 43.298% (-2.1%) from 45.41%
16896410642

push

github

Xevion
feat!: implement proper error handling, drop most expect() & unwrap() usages

126 of 337 new or added lines in 10 files covered. (37.39%)

8 existing lines in 5 files now uncovered.

743 of 1716 relevant lines covered (43.3%)

280.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/error.rs
1
//! Centralized error types for the Pac-Man game.
2
//!
3
//! This module defines all error types used throughout the application,
4
//! providing a consistent error handling approach.
5

6
use thiserror::Error;
7

8
/// Main error type for the Pac-Man game.
9
///
10
/// This is the primary error type that should be used in public APIs.
11
/// It can represent any error that can occur during game operation.
12
#[derive(Error, Debug)]
13
pub enum GameError {
14
    #[error("Asset error: {0}")]
15
    Asset(#[from] crate::asset::AssetError),
16

17
    #[error("Platform error: {0}")]
18
    Platform(#[from] crate::platform::PlatformError),
19

20
    #[error("Map parsing error: {0}")]
21
    MapParse(#[from] crate::map::parser::ParseError),
22

23
    #[error("Map error: {0}")]
24
    Map(#[from] MapError),
25

26
    #[error("Texture error: {0}")]
27
    Texture(#[from] TextureError),
28

29
    #[error("Entity error: {0}")]
30
    Entity(#[from] EntityError),
31

32
    #[error("Game state error: {0}")]
33
    GameState(#[from] GameStateError),
34

35
    #[error("SDL error: {0}")]
36
    Sdl(String),
37

38
    #[error("IO error: {0}")]
39
    Io(#[from] std::io::Error),
40

41
    #[error("Serialization error: {0}")]
42
    Serialization(#[from] serde_json::Error),
43

44
    #[error("Invalid state: {0}")]
45
    InvalidState(String),
46

47
    #[error("Resource not found: {0}")]
48
    NotFound(String),
49

50
    #[error("Configuration error: {0}")]
51
    Config(String),
52
}
53

54
/// Errors related to texture operations.
55
#[derive(Error, Debug)]
56
pub enum TextureError {
57
    #[error("Animated texture error: {0}")]
58
    Animated(#[from] crate::texture::animated::AnimatedTextureError),
59

60
    #[error("Failed to load texture: {0}")]
61
    LoadFailed(String),
62

63
    #[error("Texture not found in atlas: {0}")]
64
    AtlasTileNotFound(String),
65

66
    #[error("Invalid texture format: {0}")]
67
    InvalidFormat(String),
68

69
    #[error("Rendering failed: {0}")]
70
    RenderFailed(String),
71
}
72

73
/// Errors related to entity operations.
74
#[derive(Error, Debug)]
75
pub enum EntityError {
76
    #[error("Node not found in graph: {0}")]
77
    NodeNotFound(usize),
78

79
    #[error("Edge not found: from {from} to {to}")]
80
    EdgeNotFound { from: usize, to: usize },
81

82
    #[error("Invalid movement: {0}")]
83
    InvalidMovement(String),
84

85
    #[error("Pathfinding failed: {0}")]
86
    PathfindingFailed(String),
87
}
88

89
/// Errors related to game state operations.
90
#[derive(Error, Debug)]
91
pub enum GameStateError {}
92

93
/// Errors related to map operations.
94
#[derive(Error, Debug)]
95
pub enum MapError {
96
    #[error("Node not found: {0}")]
97
    NodeNotFound(usize),
98

99
    #[error("Invalid map configuration: {0}")]
100
    InvalidConfig(String),
101
}
102

103
/// Result type for game operations.
104
pub type GameResult<T> = Result<T, GameError>;
105

106
/// Helper trait for converting other error types to GameError.
107
pub trait IntoGameError<T> {
108
    #[allow(dead_code)]
109
    fn into_game_error(self) -> GameResult<T>;
110
}
111

112
impl<T, E> IntoGameError<T> for Result<T, E>
113
where
114
    E: std::error::Error + Send + Sync + 'static,
115
{
NEW
116
    fn into_game_error(self) -> GameResult<T> {
×
NEW
117
        self.map_err(|e| GameError::InvalidState(e.to_string()))
×
NEW
118
    }
×
119
}
120

121
/// Helper trait for converting Option to GameResult with a custom error.
122
pub trait OptionExt<T> {
123
    #[allow(dead_code)]
124
    fn ok_or_game_error<F>(self, f: F) -> GameResult<T>
125
    where
126
        F: FnOnce() -> GameError;
127
}
128

129
impl<T> OptionExt<T> for Option<T> {
NEW
130
    fn ok_or_game_error<F>(self, f: F) -> GameResult<T>
×
NEW
131
    where
×
NEW
132
        F: FnOnce() -> GameError,
×
NEW
133
    {
×
NEW
134
        self.ok_or_else(f)
×
NEW
135
    }
×
136
}
137

138
/// Helper trait for converting Result to GameResult with context.
139
pub trait ResultExt<T, E> {
140
    #[allow(dead_code)]
141
    fn with_context<F>(self, f: F) -> GameResult<T>
142
    where
143
        F: FnOnce(&E) -> GameError;
144
}
145

146
impl<T, E> ResultExt<T, E> for Result<T, E>
147
where
148
    E: std::error::Error + Send + Sync + 'static,
149
{
NEW
150
    fn with_context<F>(self, f: F) -> GameResult<T>
×
NEW
151
    where
×
NEW
152
        F: FnOnce(&E) -> GameError,
×
NEW
153
    {
×
NEW
154
        self.map_err(|e| f(&e))
×
NEW
155
    }
×
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc