mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Game] Remove instances of using unwrap without handling the panics
This commit is contained in:
parent
d97bd68ada
commit
7cfecbfff9
2 changed files with 9 additions and 9 deletions
|
|
@ -8,7 +8,7 @@ Games:
|
||||||
|
|
||||||
Protocols:
|
Protocols:
|
||||||
- Quake 2: Fixed a bug where the version tag wouldn't always be present.
|
- Quake 2: Fixed a bug where the version tag wouldn't always be present.
|
||||||
- The Ship: Fixed some instances of using `unwrap` without handling the panics.
|
- The Ship: Removed instances of using `unwrap` without handling the panics.
|
||||||
|
|
||||||
Crate:
|
Crate:
|
||||||
- Rich errors, capturing backtrace is done on `RUST_BACKTRACE=1`.
|
- Rich errors, capturing backtrace is done on `RUST_BACKTRACE=1`.
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ pub struct TheShipPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TheShipPlayer {
|
impl TheShipPlayer {
|
||||||
pub fn new_from_valve_player(player: &ServerPlayer) -> Self {
|
pub fn new_from_valve_player(player: &ServerPlayer) -> GDResult<Self> {
|
||||||
Self {
|
Ok(Self {
|
||||||
name: player.name.clone(),
|
name: player.name.clone(),
|
||||||
score: player.score,
|
score: player.score,
|
||||||
duration: player.duration,
|
duration: player.duration,
|
||||||
deaths: player.deaths.unwrap(), // TODO! Err here!
|
deaths: player.deaths.ok_or(PacketBad)?,
|
||||||
money: player.money.unwrap(), // TODO! Err here!
|
money: player.money.ok_or(PacketBad)?,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,10 +105,10 @@ impl Response {
|
||||||
players_online: response.info.players_online,
|
players_online: response.info.players_online,
|
||||||
players: response
|
players: response
|
||||||
.players
|
.players
|
||||||
.unwrap()
|
.ok_or(PacketBad)?
|
||||||
.iter()
|
.iter()
|
||||||
.map(TheShipPlayer::new_from_valve_player)
|
.map(TheShipPlayer::new_from_valve_player)
|
||||||
.collect(),
|
.collect::<GDResult<Vec<TheShipPlayer>>>()?,
|
||||||
players_maximum: response.info.players_maximum,
|
players_maximum: response.info.players_maximum,
|
||||||
players_bots: response.info.players_bots,
|
players_bots: response.info.players_bots,
|
||||||
server_type: response.info.server_type,
|
server_type: response.info.server_type,
|
||||||
|
|
@ -119,7 +119,7 @@ impl Response {
|
||||||
tv_port,
|
tv_port,
|
||||||
tv_name,
|
tv_name,
|
||||||
keywords,
|
keywords,
|
||||||
rules: response.rules.unwrap(),
|
rules: response.rules.ok_or(PacketBad)?,
|
||||||
mode: the_unwrapped_ship.mode,
|
mode: the_unwrapped_ship.mode,
|
||||||
witnesses: the_unwrapped_ship.witnesses,
|
witnesses: the_unwrapped_ship.witnesses,
|
||||||
duration: the_unwrapped_ship.duration,
|
duration: the_unwrapped_ship.duration,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue