From 0a4a4019533fd84161726381ef31af482bc893d8 Mon Sep 17 00:00:00 2001 From: snow flurry Date: Mon, 10 Jul 2023 14:46:19 -0700 Subject: [PATCH] VdfValue::into_vec: better error handling --- src/main.rs | 1 + src/vdf.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index b530733..8ffcfce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,7 @@ fn get_shortcuts(path: PathBuf) -> Result, String> { let vec: Result, String> = vdf_map["shortcuts"] .clone() .into_vec() + .map_or_else(|| Err("Malformed shortcuts.vdf".to_owned()), Ok)? .into_iter() .map(|x| { if let vdf::VdfValue::Dict(dict) = x { diff --git a/src/vdf.rs b/src/vdf.rs index 50c56e3..10aeb32 100644 --- a/src/vdf.rs +++ b/src/vdf.rs @@ -28,12 +28,12 @@ pub enum VdfValue { } impl VdfValue { - pub fn into_vec(self) -> Vec { + pub fn into_vec(self) -> Option> { if let VdfValue::Dict(dict) = self { // lazily assuming this is an array of strings - dict.into_values().collect() + Some(dict.into_values().collect()) } else { - panic!("Not a Dict! (maybe this should be less brutal of error mgmt!)"); + None } } }