From 76da13d99ea4246c0184fb0b1623b70bb87bd4fa Mon Sep 17 00:00:00 2001 From: AshleyFlow Date: Thu, 17 Oct 2024 12:39:56 +0330 Subject: [PATCH] eliminate unnecessary checks for files --- crates/lune-std/src/globals/require/context.rs | 6 ------ crates/lune-std/src/luaurc.rs | 9 +++++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/lune-std/src/globals/require/context.rs b/crates/lune-std/src/globals/require/context.rs index 75b4cd6..0688e44 100644 --- a/crates/lune-std/src/globals/require/context.rs +++ b/crates/lune-std/src/globals/require/context.rs @@ -156,12 +156,6 @@ impl RequireContext { } } - if !fs::try_exists(&path_abs).await? { - return Err(RequireError::InvalidRequire( - path_rel.to_string_lossy().to_string(), - )); - } - let content = fs::read_to_string(&path_abs).await?; let thread = lua .load(&content) diff --git a/crates/lune-std/src/luaurc.rs b/crates/lune-std/src/luaurc.rs index 50fb066..b5d6d0b 100644 --- a/crates/lune-std/src/luaurc.rs +++ b/crates/lune-std/src/luaurc.rs @@ -84,9 +84,14 @@ impl RequireAlias { } } +/** +# Errors + +* when `serde_json` fails to deserialize content of the file + + */ async fn parse_luaurc(_: &mlua::Lua, path: &PathBuf) -> Result, LuaurcError> { - if fs::try_exists(path).await? { - let content = fs::read(path).await?; + if let Ok(content) = fs::read(path).await { serde_json::from_slice(&content) .map(Some) .map_err(|err| LuaurcError::FilaedToParse(path.clone(), err))