From 39870f6b879d58f103f96165b497aee704a761f7 Mon Sep 17 00:00:00 2001
From: Someon1e <142684596+Someon1e@users.noreply.github.com>
Date: Sun, 24 Mar 2024 22:35:41 +0000
Subject: [PATCH] Throw syntax error instead of runtime error

---
 src/lune/globals/require/path.rs | 42 ++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/lune/globals/require/path.rs b/src/lune/globals/require/path.rs
index 50e4a35..b289c8e 100644
--- a/src/lune/globals/require/path.rs
+++ b/src/lune/globals/require/path.rs
@@ -29,13 +29,15 @@ where
     // 1. Try to require the exact path
     match require_inner(lua, ctx, &abs_path, &rel_path).await {
         Ok(res) => return Ok(res),
-        Err(LuaError::SyntaxError {
-            message,
-            incomplete_input: _,
-        }) => {
-            return Err(LuaError::runtime(message));
+        Err(error) => {
+            if let LuaError::SyntaxError {
+                message: _,
+                incomplete_input: _,
+            } = error
+            {
+                return Err(error);
+            }
         }
-        Err(_) => {}
     }
 
     // 2. Try to require the path with an added "luau" extension
@@ -50,13 +52,15 @@ where
         .await
         {
             Ok(res) => return Ok(res),
-            Err(LuaError::SyntaxError {
-                message,
-                incomplete_input: _,
-            }) => {
-                return Err(LuaError::runtime(message));
+            Err(error) => {
+                if let LuaError::SyntaxError {
+                    message: _,
+                    incomplete_input: _,
+                } = error
+                {
+                    return Err(error);
+                }
             }
-            Err(_) => {}
         }
     }
 
@@ -77,13 +81,15 @@ where
         .await
         {
             Ok(res) => return Ok(res),
-            Err(LuaError::SyntaxError {
-                message,
-                incomplete_input: _,
-            }) => {
-                return Err(LuaError::runtime(message));
+            Err(error) => {
+                if let LuaError::SyntaxError {
+                    message: _,
+                    incomplete_input: _,
+                } = error
+                {
+                    return Err(error);
+                }
             }
-            Err(_) => {}
         }
     }