use custom errors in VmcExtMidiCcBit
This commit is contained in:
parent
75a541cc2a
commit
20142c6922
10
src/lib.rs
10
src/lib.rs
|
@ -707,15 +707,15 @@ impl MessageBehavior for VmcExtMidiCcBit {
|
||||||
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 {
|
if msg.args.len() != 2 {
|
||||||
return Err(String::from("arg count invalid"));
|
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![2], actual: msg.args.len(), addr: msg.addr}));
|
||||||
}
|
}
|
||||||
let knob: i32;
|
let knob: i32;
|
||||||
let active: bool;
|
let active: bool;
|
||||||
match msg.args[0] {
|
match msg.args[0] {
|
||||||
OscType::Int(i) => knob = i,
|
OscType::Int(i) => knob = i,
|
||||||
_ => 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] {
|
match msg.args[1] {
|
||||||
OscType::Int(i) => {
|
OscType::Int(i) => {
|
||||||
|
@ -724,10 +724,10 @@ impl MessageBehavior for VmcExtMidiCcBit {
|
||||||
} else if i == 1 {
|
} else if i == 1 {
|
||||||
active = true;
|
active = true;
|
||||||
} else {
|
} 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: 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})),
|
||||||
}
|
}
|
||||||
return Ok(VmcExtMidiCcBit { knob, active });
|
return Ok(VmcExtMidiCcBit { knob, active });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user