diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-11-13 12:09:02 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-11-13 12:09:02 +0100 |
commit | d98c391571ac41af08757c3fb87beef0a6415d23 (patch) | |
tree | b3744e7de930f3fd13e82a80720ff84002c3c4ee | |
parent | 0aee5f34c9f384656740666c6fdc03ccf537d2a3 (diff) | |
download | evtclib-d98c391571ac41af08757c3fb87beef0a6415d23.tar.gz evtclib-d98c391571ac41af08757c3fb87beef0a6415d23.tar.bz2 evtclib-d98c391571ac41af08757c3fb87beef0a6415d23.zip |
Document panic in Log::boss and remove other panic
Overall, evtclib is doing quite well on the .unwrap()/.expect()/panic!()
calls, except for some doctests (which can be changed at some point) and
the actual tests.
One case where we do panic (and should document it!) is Log::boss. The
documentation has been added there.
Another (rare if not impossible for proper evtc files) case was the
conversion of the language event, which assumed that we will definitely
be able to convert the u64 to the right language. In all normal cases
this should be true, but if evtclib deals with untrusted input, we might
not want to panic a whole program because someone smuggled in a
malicious file.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/event.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 5 |
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5701aa7..92c594b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file. - Boss and encounter definitions for the training golems (`StandardKittyGolem`, `MediumKittyGolem`, `LargeKittyGolem`) - `Log::is_generic` to check whether a log is generic (WvW) +- `FromRawEventError::UnknownLanguage` has been added to deal with an invalid + language byte. ### Fixed - `evtclib` will no longer choke on WvW logs where player names might not contain the expected diff --git a/src/event.rs b/src/event.rs index 4d02fe7..ee561f8 100644 --- a/src/event.rs +++ b/src/event.rs @@ -19,6 +19,8 @@ pub enum FromRawEventError { UnknownStateChange(raw::CbtStateChange), #[error("event contains an unknown damage event")] UnknownDamageEvent, + #[error("an unknown language byte was found")] + UnknownLanguage, #[error("the event contains invalid text")] InvalidText, #[error("an unexpected REPLINFO was found")] @@ -338,7 +340,8 @@ impl TryFrom<&raw::CbtEvent> for Event { agent_addr: raw_event.src_agent, }, CbtStateChange::Language => EventKind::Language { - language: raw::Language::from_u64(raw_event.src_agent).unwrap(), + language: raw::Language::from_u64(raw_event.src_agent) + .ok_or(FromRawEventError::UnknownLanguage)?, }, CbtStateChange::GwBuild => EventKind::Build { build: raw_event.src_agent, @@ -188,6 +188,11 @@ impl Log { /// /// Be careful with encounters that have multiple boss agents, such as Trio /// and Xera. + /// + /// # Panics + /// + /// This function will panic if the boss agent cannot be found. For a more failsafe version, + /// see [`Log::boss_agents`]. pub fn boss(&self) -> &Agent { self.characters() .find(|c| c.character().id() == self.boss_id) |