From d36487e28f7d69d2f48b23f9df038dec3568136d Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 10 Dec 2024 15:11:27 -0800 Subject: [PATCH] caution: don't crash on unknown keyword Fixes: 34f0c3b0ce05 ("serialization for DecksCache") --- src/storage/decks.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/storage/decks.rs b/src/storage/decks.rs index 6034468..cd4d066 100644 --- a/src/storage/decks.rs +++ b/src/storage/decks.rs @@ -174,13 +174,15 @@ impl MetadataKeyword { } impl fmt::Display for MetadataKeyword { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let name = MetadataKeyword::MAPPING + if let Some(name) = MetadataKeyword::MAPPING .iter() .find(|(_, keyword)| keyword == self) .map(|(name, _)| *name) - .expect("MAPPING is incorrect"); - - write!(f, "{}", name) + { + write!(f, "{}", name) + } else { + write!(f, "UnknownMetadataKeyword") + } } } @@ -407,13 +409,15 @@ impl Keyword { impl fmt::Display for Keyword { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let name = Keyword::MAPPING + if let Some(name) = Keyword::MAPPING .iter() .find(|(_, keyword, _)| keyword == self) .map(|(name, _, _)| *name) - .expect("MAPPING is incorrect"); - - write!(f, "{}", name) + { + write!(f, "{}", name) + } else { + write!(f, "UnknownKeyword") + } } }