VdfValue::into_vec: better error handling

This commit is contained in:
snow flurry 2023-07-10 14:46:19 -07:00
parent 3e6d025b74
commit 0a4a401953
2 changed files with 4 additions and 3 deletions

View file

@ -149,6 +149,7 @@ fn get_shortcuts(path: PathBuf) -> Result<Vec<NonSteamGame>, String> {
let vec: Result<Vec<NonSteamGame>, 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 {

View file

@ -28,12 +28,12 @@ pub enum VdfValue {
}
impl VdfValue {
pub fn into_vec(self) -> Vec<VdfValue> {
pub fn into_vec(self) -> Option<Vec<VdfValue>> {
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
}
}
}