node: less unwraps (#6388)

* Update api/node/rust/interpreter/value.rs

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
This commit is contained in:
FloVanGH 2024-10-01 08:47:53 +00:00 committed by GitHub
parent 68a4e15cff
commit 4b880a7b49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 171 additions and 17 deletions

View file

@ -239,7 +239,14 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
let mut vec = vec![];
for i in 0..array.len() {
vec.push(to_value(env, array.get(i)?.unwrap(), a)?);
vec.push(to_value(
env,
array.get(i)?.ok_or(napi::Error::from_reason(format!(
"Cannot access array element at index {}",
i
)))?,
a,
)?);
}
Ok(Value::Model(ModelRc::new(SharedVectorModel::from(SharedVector::from_slice(
&vec,