use custom errors in VmcExtVrm

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 12:13:09 -05:00
parent 3766cd2104
commit 6acdcaab6a
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -980,25 +980,25 @@ impl MessageBehavior for VmcExtVrm {
args, args,
}; };
} }
fn from_osc_message(msg: OscMessage) -> Result<Self, String> { fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
if msg.args.len() < 2 || msg.args.len() > 3 { if msg.args.len() < 2 || msg.args.len() > 3 {
return Err(String::from("arg count invalid")); return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![2, 3], actual: msg.args.len(), addr: msg.addr}));
} }
let path: String; let path: String;
let title: String; let title: String;
let mut hash: Option<String> = None; let mut hash: Option<String> = None;
match &msg.args[0] { match &msg.args[0] {
OscType::String(s) => path = s.to_owned(), OscType::String(s) => path = s.to_owned(),
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
} }
match &msg.args[1] { match &msg.args[1] {
OscType::String(s) => title = s.to_owned(), OscType::String(s) => title = s.to_owned(),
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})),
} }
if msg.args.len() == 3 { if msg.args.len() == 3 {
match &msg.args[2] { match &msg.args[2] {
OscType::String(s) => hash = Some(s.to_owned()), OscType::String(s) => hash = Some(s.to_owned()),
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[2], addr: msg.addr, arg_count: 2})),
} }
} }
return Ok(VmcExtVrm { path, title, hash }); return Ok(VmcExtVrm { path, title, hash });