lapis
lapis copied to clipboard
Don't know how to write: (boolean) false
I'm getting the following in the nginx log:
2018/04/07 18:16:21 [error] 25437#25437: *6 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/lapis/request.lua:85: Don't know how to write: (boolean) false
stack traceback:
coroutine 0:
[C]: in function 'error'
/usr/local/share/lua/5.1/lapis/request.lua:85: in function 'write'
/usr/local/share/lua/5.1/lapis/application.lua:141: in function 'render_error_request'
/usr/local/share/lua/5.1/lapis/application.lua:173: in function 'dispatch'
/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function 'serve'
render_error_request()
indeed passes to write()
a table containing a boolean value which write()
doesn't know how to print.
render_error_request() indeed passes to write() a table containing a boolean value which write() doesn't know how to print.
That sounds right, there is no write handler for the value false
. Is there a reason why you're passing that table?
It's not me, it's rather this code in application.lua
: https://github.com/leafo/lapis/blob/master/lapis/application.lua#L207
handle_error()
returns a table containing a boolean value. The table is then passed to write()
: https://github.com/leafo/lapis/blob/master/lapis/application.lua#L141
Did you override the implementation of any of those methods? I can't see how the default code could pass false into write
I'm trying to put up my own site running https://github.com/luarocks/luarocks-site. As I understand it (I'm not much into web development), it fails to connect to a DB due to a credentials problem, which raises an error, but lapis fails to render that error correctly due to the code I referenced previously. So instead of a meaningful error message I get an empty HTTP 500 page.
I did a quick look at the luarocks-site project and I don't see any obvious indicators, if you want to try two things:
- Does a fresh lapis project have the same erorr?
- If you disable exception tracking does the error go away? temporarily comment out this line https://github.com/luarocks/luarocks-site/blob/master/app.moon#L56 (if you don't have moonscript compiler set up you may want to edit the lua file directly for this test)
Thanks for looking into it.
- I pulled lapis from LuaRocks a couple of weeks ago, so I guess it's relatively fresh.
- if I comment out exception tracking, this is what I get:
Error
/usr/local/share/lua/5.1/pgmoon/init.lua:271: missing password, required for connect
Traceback
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.1/pgmoon/init.lua:271: in function 'auth'
/usr/local/share/lua/5.1/pgmoon/init.lua:211: in function 'connect'
/usr/local/share/lua/5.1/lapis/db/postgres.lua:58: in function 'select'
/usr/local/share/lua/5.1/lapis/db/base_model.lua:562: in function 'find'
./models/manifests.lua:237: in function 'root'
./app.lua:58: in function 'handler'
/usr/local/share/lua/5.1/lapis/application.lua:130: in function 'resolve'
/usr/local/share/lua/5.1/lapis/application.lua:161: in function </usr/local/share/lua/5.1/lapis/application.lua:159>
[C]: in function 'xpcall'
/usr/local/share/lua/5.1/lapis/application.lua:159: in function 'dispatch'
/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function 'serve'
content_by_lua(nginx.conf.compiled:35):1: in function <content_by_lua(nginx.conf.compiled:35):1>
The root cause is a database access failure. I know how to fix it, the request here is to make it more intuitive. The way it is reported now is a generic server HTTP 500 error for the reasons described above. As I understand, either request.lua:write()
should be changed to accept boolean values, or application.lua:handle_error()
should be changed to not return a boolean value.
thanks for testing it, it looks like lapis-exceptions is returning an invalid object for you. I'll take a closer look. Just to verify, what version of lapis-exceptions are you on? https://luarocks.org/modules/leafo/lapis-exceptions
Can you try the development version if you aren't on it
$ luarocks show lapis-exceptions
lapis-exceptions 1.0.0-1 - Track Lapis exceptions to database and email when they happen
License: MIT
Installed in: /usr/local
Modules:
lapis.exceptions.email (/usr/local/share/lua/5.1/lapis/exceptions/email.lua)
lapis.exceptions.models (/usr/local/share/lua/5.1/lapis/exceptions/models.lua)
lapis.features.exception_tracking (/usr/local/share/lua/5.1/lapis/features/exception_tracking.lua)
Depends on:
lua-cjson
date
mimetypes
ansicolors
pgmoon
lpeg
etlua
loadkit
luasocket
luaossl
lapis
luafilesystem
luabitop
$ sudo luarocks install lapis-exceptions dev-1
Warning: falling back to wget - install luasec to get native HTTPS support
Error: No results matching query were found.
Hi, same error here. I'm running macOS and trying to standup a luarocks site instance. The homepage loads, next request the above error occurs.
Hi, same error here too. I'm runing centos 7.
I solved this problem, the root cause of the problem is that the password of the postgres database is missing. just make the following changes https://github.com/luarocks/luarocks-site/blob/master/config.moon#L19 Add a new line like: password: "xxxx"
I'm not able to reproduce the error originally reported so I'm closing this ticket out. Unclear if the others who posted here had original error, or the one about not setting their database password.
The other error being reported here, missing password, required for connect
, is being displayed because you configured your Postgres database to require password based authentication, but you did not provide a password in your Lapis app's configuration. This is not a Lapis bug, but an issue with your app's configuration. Provide the correct password in the configuration for Postgres if you want to connect to your database.
https://leafo.net/lapis/reference/database.html#establishing-a-connection/postgresql
I have the same problem as @zhongweikang , aka lapis can't connect to my postgresql database: missing password, required for connect
.
Is https://github.com/leafo/lapis/issues/612#issuecomment-627083507 the recommended way to set the password ? it looks insecure to hardcode it there. I see a folder secret_example but not sure how to use that scheme.
Other question: how can I set the postgresql port ?
@teto This error displays because you configured your database to require password based authentication, but you did not provide a password in your Lapis app's configuration. This is not a Lapis bug.
You'll want to provide the password in your config. The config file is a regular Lua/MoonScript file, so if you are uncomfortable writing it to a file and want to reference a value from another source, say an environment variable, you could write:
config("development", {
postgres = {
password = os.getenv("PGPASSWORD"),
-- ...
}
})
Because I know you're specifically working with luarocks-site, in that project I use a "secrets" folder convention where all secret key configuration is placed in a special directory without being checked in the main repository.
If you check the config.moon
for that project you can see a require
to the secret
module: https://github.com/luarocks/luarocks-site/blob/master/config.moon#L15
The secrect_example
directory is provided as an example secrets module for you to get started with. Duplicate that directory to the name secret
, then edit it with your secret configuration. Do not check that file into the repo.
If you're creating an automated system to deploy the app, then part of your process should be generating a secret
directory with the relevant configuration.
Other question: how can I set the postgresql port ?
The postgres
config object that is passed directly to pgmoon
, so you can use any of those options, including port
- https://leafo.net/lapis/reference/database.html#establishing-a-connection/postgresql
- https://github.com/leafo/pgmoon#newoptions