From 5dd7ce382a55172ae3ddcf27c4ddf5f48aa98e39 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Tue, 30 Mar 2021 23:56:37 -0400 Subject: [PATCH] fix: throw lua error if fs.cd fails --- golibs/fs/fs.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 6716664..88d1a5d 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -13,6 +13,11 @@ func Loader(L *lua.LState) int { return 1 } + +func LuaErr(L *lua.LState, code int) { + L.Error(lua.LNumber(code), 1) +} + var exports = map[string]lua.LGFunction{ "cd": cd, } @@ -20,7 +25,13 @@ var exports = map[string]lua.LGFunction{ func cd(L *lua.LState) int { path := L.ToString(1) - os.Chdir(path) + err := os.Chdir(path) + if err != nil { + switch err.(*os.PathError).Err.Error() { + case "no such file or directory": + LuaErr(L, 1) + } + } return 0 }