From 15503575e5ddf60fca4c8e1105b89cafb946edbf Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:17:51 -0500 Subject: [PATCH] use custom errors and fix bug in VmcExtSettingWin --- src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f8e332..588f70e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1134,9 +1134,9 @@ impl MessageBehavior for VmcExtSettingWin { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 4 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![4], actual: msg.args.len(), addr: msg.addr})); } let mut result = Self { is_top_most: false, @@ -1149,28 +1149,28 @@ impl MessageBehavior for VmcExtSettingWin { if i == 1 { result.is_top_most = true; } else if i != 0 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { if i == 1 { result.is_transparent = true; } else if i != 0 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => result.window_click_through = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } - match msg.args[2] { + match msg.args[3] { OscType::Int(i) => result.hide_border = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(result); }