Change in the prefix of messages from searchers
The initial "\n\t" to properly indent a searcher message is being added by 'findloader' when building the error message, instead of being included in the original message by each searcher itself.
This commit is contained in:
12
loadlib.c
12
loadlib.c
@@ -464,7 +464,7 @@ static const char *getnextfilename (char **path, char *end) {
|
|||||||
static void pusherrornotfound (lua_State *L, const char *path) {
|
static void pusherrornotfound (lua_State *L, const char *path) {
|
||||||
luaL_Buffer b;
|
luaL_Buffer b;
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
luaL_addstring(&b, "\n\tno file '");
|
luaL_addstring(&b, "no file '");
|
||||||
luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '");
|
luaL_addgsub(&b, path, LUA_PATH_SEP, "'\n\tno file '");
|
||||||
luaL_addstring(&b, "'");
|
luaL_addstring(&b, "'");
|
||||||
luaL_pushresult(&b);
|
luaL_pushresult(&b);
|
||||||
@@ -591,7 +591,7 @@ static int searcher_Croot (lua_State *L) {
|
|||||||
if (stat != ERRFUNC)
|
if (stat != ERRFUNC)
|
||||||
return checkload(L, 0, filename); /* real error */
|
return checkload(L, 0, filename); /* real error */
|
||||||
else { /* open function not found */
|
else { /* open function not found */
|
||||||
lua_pushfstring(L, "\n\tno module '%s' in file '%s'", name, filename);
|
lua_pushfstring(L, "no module '%s' in file '%s'", name, filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,7 +604,7 @@ static int searcher_preload (lua_State *L) {
|
|||||||
const char *name = luaL_checkstring(L, 1);
|
const char *name = luaL_checkstring(L, 1);
|
||||||
lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
|
lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
|
||||||
if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */
|
if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */
|
||||||
lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
|
lua_pushfstring(L, "no field package.preload['%s']", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -623,8 +623,10 @@ static void findloader (lua_State *L, const char *name) {
|
|||||||
luaL_buffinit(L, &msg);
|
luaL_buffinit(L, &msg);
|
||||||
/* iterate over available searchers to find a loader */
|
/* iterate over available searchers to find a loader */
|
||||||
for (i = 1; ; i++) {
|
for (i = 1; ; i++) {
|
||||||
|
luaL_addstring(&msg, "\n\t"); /* error-message prefix */
|
||||||
if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */
|
if (lua_rawgeti(L, 3, i) == LUA_TNIL) { /* no more searchers? */
|
||||||
lua_pop(L, 1); /* remove nil */
|
lua_pop(L, 1); /* remove nil */
|
||||||
|
luaL_buffsub(&msg, 2); /* remove prefix */
|
||||||
luaL_pushresult(&msg); /* create error message */
|
luaL_pushresult(&msg); /* create error message */
|
||||||
luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
|
luaL_error(L, "module '%s' not found:%s", name, lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
@@ -636,8 +638,10 @@ static void findloader (lua_State *L, const char *name) {
|
|||||||
lua_pop(L, 1); /* remove extra return */
|
lua_pop(L, 1); /* remove extra return */
|
||||||
luaL_addvalue(&msg); /* concatenate error message */
|
luaL_addvalue(&msg); /* concatenate error message */
|
||||||
}
|
}
|
||||||
else
|
else { /* no error message */
|
||||||
lua_pop(L, 2); /* remove both returns */
|
lua_pop(L, 2); /* remove both returns */
|
||||||
|
luaL_buffsub(&msg, 2); /* remove prefix */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,29 @@ do
|
|||||||
package.path = oldpath
|
package.path = oldpath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
do print"testing 'require' message"
|
||||||
|
local oldpath = package.path
|
||||||
|
local oldcpath = package.cpath
|
||||||
|
|
||||||
|
package.path = "?.lua;?/?"
|
||||||
|
package.cpath = "?.so;?/init"
|
||||||
|
|
||||||
|
local st, msg = pcall(require, 'XXX')
|
||||||
|
|
||||||
|
local expected = [[module 'XXX' not found:
|
||||||
|
no field package.preload['XXX']
|
||||||
|
no file 'XXX.lua'
|
||||||
|
no file 'XXX/XXX'
|
||||||
|
no file 'XXX.so'
|
||||||
|
no file 'XXX/init']]
|
||||||
|
|
||||||
|
assert(msg == expected)
|
||||||
|
|
||||||
|
package.path = oldpath
|
||||||
|
package.cpath = oldcpath
|
||||||
|
end
|
||||||
|
|
||||||
print('+')
|
print('+')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user