Skip to content

Commit

Permalink
refactor: handle RLE decoding errors in 'Map::from_str'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed May 17, 2024
1 parent 4a49836 commit 83ef553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub enum ParseMapError {
/// Contains non-XSB format character.
#[error("invalid character: `{0}`")]
InvalidCharacter(char),
/// RLE decoding error occurred.
#[error(transparent)]
DecodeRleError(#[from] DecodeRleError),
/// Actions are invalid and cannot be used to build and create levels.
#[error("invalid actions")]
InvalidActions,
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl FromStr for Map {
}
// If the `line` contains digits, perform RLE decoding
if line.chars().any(char::is_numeric) {
line = rle_decode(&line).unwrap();
line = rle_decode(&line)?;
}
dimensions.x = dimensions.x.max(line.len() as i32);
dimensions.y += 1;
Expand Down

0 comments on commit 83ef553

Please sign in to comment.