Prepend @ to Lua paths in redbean to recognize them as paths in error messages

This commit is contained in:
Paul Kulchenko 2021-08-11 21:57:18 -07:00
parent 13e50ab2b6
commit 5e87b05e02

View file

@ -3200,12 +3200,13 @@ static char *ServeLua(struct Asset *a, const char *s, size_t n) {
effectivepath.p = s; effectivepath.p = s;
effectivepath.n = n; effectivepath.n = n;
if ((code = FreeLater(LoadAsset(a, &codelen)))) { if ((code = FreeLater(LoadAsset(a, &codelen)))) {
int status = luaL_loadbuffer(L, code, codelen, FreeLater(strndup(s, n))); int status = luaL_loadbuffer(L, code, codelen,
FreeLater(xasprintf("@%s", FreeLater(strndup(s, n)))));
if (status == LUA_OK && LuaCallWithTrace(L, 0, 0) == LUA_OK) { if (status == LUA_OK && LuaCallWithTrace(L, 0, 0) == LUA_OK) {
return CommitOutput(GetLuaResponse()); return CommitOutput(GetLuaResponse());
} else { } else {
char *error; char *error;
WARNF("failed to run lua code %s", lua_tostring(L, -1)); WARNF("failed to run lua code: %s", lua_tostring(L, -1));
error = ServeErrorWithDetail(500, "Internal Server Error", error = ServeErrorWithDetail(500, "Internal Server Error",
IsLoopbackClient() ? lua_tostring(L, -1) : NULL); IsLoopbackClient() ? lua_tostring(L, -1) : NULL);
lua_pop(L, 1); lua_pop(L, 1);
@ -5453,7 +5454,8 @@ static bool LuaRun(const char *path, bool mandatory) {
effectivepath.p = path; effectivepath.p = path;
effectivepath.n = pathlen; effectivepath.n = pathlen;
DEBUGF("LuaRun(%`'s)", path); DEBUGF("LuaRun(%`'s)", path);
status = luaL_loadbuffer(L, code, codelen, path); status = luaL_loadbuffer(L, code, codelen,
FreeLater(xasprintf("@%s", path)));
if (status != LUA_OK || LuaCallWithTrace(L, 0, 0) != LUA_OK) { if (status != LUA_OK || LuaCallWithTrace(L, 0, 0) != LUA_OK) {
WARNF("script failed to run: %s", lua_tostring(L, -1)); WARNF("script failed to run: %s", lua_tostring(L, -1));
lua_pop(L, 1); lua_pop(L, 1);