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

Xevion / Pac-Man / 17012447928

16 Aug 2025 08:12PM UTC coverage: 38.85% (-12.3%) from 51.196%
17012447928

Pull #3

github

Xevion
chore: add cargo checks to pre-commit
Pull Request #3: ECS Refactor

161 of 1172 new or added lines in 23 files covered. (13.74%)

9 existing lines in 4 files now uncovered.

777 of 2000 relevant lines covered (38.85%)

101.8 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 std::io;
7

8
use bevy_ecs::event::Event;
9

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

19
    #[error("Platform error: {0}")]
20
    Platform(#[from] PlatformError),
21

22
    #[error("Map parsing error: {0}")]
23
    MapParse(#[from] ParseError),
24

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

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

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

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

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

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

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

47
#[derive(thiserror::Error, Debug)]
48
pub enum AssetError {
49
    #[error("IO error: {0}")]
50
    Io(#[from] io::Error),
51

52
    #[error("Asset not found: {0}")]
53
    NotFound(String),
54
}
55

56
/// Platform-specific errors.
57
#[derive(thiserror::Error, Debug)]
58
#[allow(dead_code)]
59
pub enum PlatformError {
60
    #[error("Console initialization failed: {0}")]
61
    ConsoleInit(String),
62
    #[error("Platform-specific error: {0}")]
63
    Other(String),
64
}
65

66
/// Error type for map parsing operations.
67
#[derive(thiserror::Error, Debug)]
68
pub enum ParseError {
69
    #[error("Unknown character in board: {0}")]
70
    UnknownCharacter(char),
71
    #[error("House door must have exactly 2 positions, found {0}")]
72
    InvalidHouseDoorCount(usize),
73
    #[error("Map parsing failed: {0}")]
74
    ParseFailed(String),
75
}
76

77
/// Errors related to texture operations.
78
#[derive(thiserror::Error, Debug)]
79
pub enum TextureError {
80
    #[error("Animated texture error: {0}")]
81
    Animated(#[from] AnimatedTextureError),
82

83
    #[error("Failed to load texture: {0}")]
84
    LoadFailed(String),
85

86
    #[error("Texture not found in atlas: {0}")]
87
    AtlasTileNotFound(String),
88

89
    #[error("Invalid texture format: {0}")]
90
    InvalidFormat(String),
91

92
    #[error("Rendering failed: {0}")]
93
    RenderFailed(String),
94
}
95

96
#[derive(thiserror::Error, Debug)]
97
pub enum AnimatedTextureError {
98
    #[error("Frame duration must be positive, got {0}")]
99
    InvalidFrameDuration(f32),
100
}
101

102
/// Errors related to entity operations.
103
#[derive(thiserror::Error, Debug)]
104
pub enum EntityError {
105
    #[error("Node not found in graph: {0}")]
106
    NodeNotFound(usize),
107

108
    #[error("Edge not found: from {from} to {to}")]
109
    EdgeNotFound { from: usize, to: usize },
110
}
111

112
/// Errors related to map operations.
113
#[derive(thiserror::Error, Debug)]
114
pub enum MapError {
115
    #[error("Node not found: {0}")]
116
    NodeNotFound(usize),
117

118
    #[error("Invalid map configuration: {0}")]
119
    InvalidConfig(String),
120
}
121

122
/// Result type for game operations.
123
pub type GameResult<T> = Result<T, GameError>;
124

125
/// Helper trait for converting other error types to GameError.
126
pub trait IntoGameError<T> {
127
    #[allow(dead_code)]
128
    fn into_game_error(self) -> GameResult<T>;
129
}
130

131
impl<T, E> IntoGameError<T> for Result<T, E>
132
where
133
    E: std::error::Error + Send + Sync + 'static,
134
{
UNCOV
135
    fn into_game_error(self) -> GameResult<T> {
×
136
        self.map_err(|e| GameError::InvalidState(e.to_string()))
×
137
    }
×
138
}
139

140
/// Helper trait for converting Option to GameResult with a custom error.
141
pub trait OptionExt<T> {
142
    #[allow(dead_code)]
143
    fn ok_or_game_error<F>(self, f: F) -> GameResult<T>
144
    where
145
        F: FnOnce() -> GameError;
146
}
147

148
impl<T> OptionExt<T> for Option<T> {
UNCOV
149
    fn ok_or_game_error<F>(self, f: F) -> GameResult<T>
×
150
    where
×
151
        F: FnOnce() -> GameError,
×
152
    {
×
153
        self.ok_or_else(f)
×
154
    }
×
155
}
156

157
/// Helper trait for converting Result to GameResult with context.
158
pub trait ResultExt<T, E> {
159
    #[allow(dead_code)]
160
    fn with_context<F>(self, f: F) -> GameResult<T>
161
    where
162
        F: FnOnce(&E) -> GameError;
163
}
164

165
impl<T, E> ResultExt<T, E> for Result<T, E>
166
where
167
    E: std::error::Error + Send + Sync + 'static,
168
{
UNCOV
169
    fn with_context<F>(self, f: F) -> GameResult<T>
×
170
    where
×
171
        F: FnOnce(&E) -> GameError,
×
172
    {
×
173
        self.map_err(|e| f(&e))
×
174
    }
×
175
}
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