From 578de55d987a8cf5d016a8b8066f25caf0434cce Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:17:37 +0800 Subject: [PATCH] Decreased the nesting for the error handling --- yazi-plugin/src/fs/fs.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index a74ee69d..c933198a 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -113,12 +113,15 @@ fn open(lua: &Lua) -> mlua::Result { } let result = open_opts.open(&*url).await; - match result { - Ok(_) => match File::cast(&lua, yazi_fs::File::from_dummy(url.clone(), None)) { - Ok(f) => (f, Value::Nil).into_lua_multi(&lua), - Err(e) => (Value::Nil, e).into_lua_multi(&lua), - }, - Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua), + let yazi_file = yazi_fs::File::from(url.clone()).await; + + match (result, yazi_file) { + (Ok(_), Ok(f)) => match File::cast(&lua, f) { + Ok(file) => (file, Value::Nil).into_lua_multi(&lua), + Err(e) => (Value::Nil, e).into_lua_multi(&lua) + } + (Err(e), _) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua), + (_, Err(e)) => (Value::Nil, e).into_lua_multi(&lua) } }) }