mirror of
https://github.com/lune-org/lune.git
synced 2025-04-11 22:10:53 +01:00
Check if not FileNotFound instead of if SyntaxError
This commit is contained in:
parent
087ecbd4f1
commit
ba9ebb2a53
1 changed files with 23 additions and 21 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
use std::io::ErrorKind;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
use mlua::Error::ExternalError;
|
||||||
|
|
||||||
use super::context::*;
|
use super::context::*;
|
||||||
|
|
||||||
|
@ -29,13 +31,9 @@ where
|
||||||
// 1. Try to require the exact path
|
// 1. Try to require the exact path
|
||||||
match require_inner(lua, ctx, &abs_path, &rel_path).await {
|
match require_inner(lua, ctx, &abs_path, &rel_path).await {
|
||||||
Ok(res) => return Ok(res),
|
Ok(res) => return Ok(res),
|
||||||
Err(error) => {
|
Err(err) => {
|
||||||
if let LuaError::SyntaxError {
|
if !is_file_not_found_error(&err) {
|
||||||
message: _,
|
return Err(err);
|
||||||
incomplete_input: _,
|
|
||||||
} = error
|
|
||||||
{
|
|
||||||
return Err(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,13 +50,9 @@ where
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(res) => return Ok(res),
|
Ok(res) => return Ok(res),
|
||||||
Err(error) => {
|
Err(err) => {
|
||||||
if let LuaError::SyntaxError {
|
if !is_file_not_found_error(&err) {
|
||||||
message: _,
|
return Err(err);
|
||||||
incomplete_input: _,
|
|
||||||
} = error
|
|
||||||
{
|
|
||||||
return Err(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,13 +75,9 @@ where
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(res) => return Ok(res),
|
Ok(res) => return Ok(res),
|
||||||
Err(error) => {
|
Err(err) => {
|
||||||
if let LuaError::SyntaxError {
|
if !is_file_not_found_error(&err) {
|
||||||
message: _,
|
return Err(err);
|
||||||
incomplete_input: _,
|
|
||||||
} = error
|
|
||||||
{
|
|
||||||
return Err(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,3 +120,15 @@ fn append_extension(path: impl Into<PathBuf>, ext: &'static str) -> PathBuf {
|
||||||
};
|
};
|
||||||
new
|
new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_file_not_found_error(err: &LuaError) -> bool {
|
||||||
|
if let ExternalError(err) = err {
|
||||||
|
if let Some(err) = err.as_ref().downcast_ref::<std::io::Error>() {
|
||||||
|
err.kind() == ErrorKind::NotFound
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue