eliminate unnecessary checks for files

This commit is contained in:
AshleyFlow 2024-10-17 12:39:56 +03:30
parent 7f07c9d107
commit 76da13d99e
2 changed files with 7 additions and 8 deletions

View file

@ -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 content = fs::read_to_string(&path_abs).await?;
let thread = lua let thread = lua
.load(&content) .load(&content)

View file

@ -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<Option<Luaurc>, LuaurcError> { async fn parse_luaurc(_: &mlua::Lua, path: &PathBuf) -> Result<Option<Luaurc>, LuaurcError> {
if fs::try_exists(path).await? { if let Ok(content) = fs::read(path).await {
let content = fs::read(path).await?;
serde_json::from_slice(&content) serde_json::from_slice(&content)
.map(Some) .map(Some)
.map_err(|err| LuaurcError::FilaedToParse(path.clone(), err)) .map_err(|err| LuaurcError::FilaedToParse(path.clone(), err))