use custom errors in VmcExtRvc

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 12:07:15 -05:00
parent 86a1d0a605
commit 577c1aa872
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -826,9 +826,9 @@ impl MessageBehavior for VmcExtRvc {
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 {
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 enable: bool;
let port: u16;
@ -840,25 +840,25 @@ impl MessageBehavior for VmcExtRvc {
} else if i == 1 {
enable = true;
} 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) => {
if i >= 0 && i <= 65535 {
port = i as u16;
} else {
return Err(String::from("arg value invalid"));
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, 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})),
}
if msg.args.len() == 3 {
match &msg.args[2] {
OscType::String(s) => ip_addr = 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(VmcExtRvc {