From c0645d928201fc5f8563374d62d90af7dadbb37c Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:00:00 -0500 Subject: [PATCH] use custom errors in VmcExtMidiNote --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ea3a708..ad76f18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -618,9 +618,9 @@ impl MessageBehavior for VmcExtMidiNote { 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 active: bool; let channel: i32; @@ -633,22 +633,22 @@ impl MessageBehavior for VmcExtMidiNote { } else if i == 0 { active = false; } else { - 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) => channel = i, - _ => 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) => note = 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[3] { OscType::Float(f) => velocity = f, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(VmcExtMidiNote { active,