Skip to content

Weird init_by_lua* behaviour around empty tables, nils, arguments in general. #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
datafatmunger opened this issue Dec 3, 2015 · 2 comments

Comments

@datafatmunger
Copy link

The easiest way to reproduce "weirdness":

init_by_lua 'print({})';

Will produce:

nginx: [error] init_by_lua error: init_by_lua:1: bad argument #1 to 'print' (string, number, boolean, or nil expected, got table)
stack traceback:
[C]: in function 'print'
init_by_lua:1: in main chunk

Strange because this works outside of Nginx fine, and even seems to work in content_by_lua.

Specifically in my case, I have similar weirdness:

local upvalues = self:readObject()
for index,upvalue in ipairs(upvalues) do
   if typeidx == LEGACY_TYPE_RECUR_FUNCTION then
      debug.setupvalue(func, index, upvalue)
   elseif upvalue.name == '_ENV' then
      debug.setupvalue(func, index, _ENV)
   else
      debug.setupvalue(func, index, upvalue.value)
   end
end

Results in:

nginx: [error] init_by_lua_file error: ...g/Development/torch/install/share/lua/5.1/torch/File.lua:241: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
    [C]: in function 'ipairs'

Again, code works fine outside of init_by_lua*

@membphis
Copy link
Contributor

membphis commented Dec 4, 2015

init_by_lua 'print({})';

https://github.com/openresty/lua-nginx-module#print
syntax: print(...)

Writes argument values into the nginx error.log file with the ngx.NOTICE log level.

if you put the print({}) to the content_by_lua, you should set your log level to notice level as blow, then you'll get the same error message.

error_log logs/error.log  notice;

for the second case, the error log have said clear very mush, the var upvalues is nil, please resolve this at first.

@agentzh
Copy link
Member

agentzh commented Dec 4, 2015

@bgraves print({}) is invalid in content_by_lua too:

2015/12/04 15:13:17 [error] 13704#0: *1 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:46):2: bad argument #1 to 'print' (string, number, boolean, or nil expected, got table)

Please try harder to provide a minimal and self-contained test case that actually works inconsistently. Thank you :)

BTW, ngx_lua overrides print as documented here:

https://github.com/openresty/lua-nginx-module#print

The behaviour is not identical to the standard Lua language's version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants