Skip to content
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

Panic on request #4

Closed
saeugetier opened this issue Feb 27, 2016 · 7 comments
Closed

Panic on request #4

saeugetier opened this issue Feb 27, 2016 · 7 comments

Comments

@saeugetier
Copy link

I tried the simple-api demo as described. The api-key is turned of.

local espress = require 'espress'
local port = 80
local server = espress.createserver(port)
server:use("routes_auto.lc")

The nodemcu crashes with this message:

Request received: GET /api/hello
routes/hello.get.lc
PANIC: unprotected error in call to Lua API (?:0: attempt to call a nil value)

Tested firmware is the newest version from http://nodemcu-build.com/ master build with modules: bit, crypto, file, gpio, net, node, tmr, uart, wifi

@loicortola
Copy link
Owner

Hi @saeugetier , let's try to figure this one out.
Can you paste the list of files uploaded to your NodeMCU for me?

My guess is that you have uploaded routes/hello.get.lc which defaults to hello.get.lc as filename (NodeMCU has a key/value file-system, filenames can have slashes).
Thus, the file routes/hello.get.lc is not found.

a simple

file.rename("hello.get.lc", "routes/hello.get.lc")

should do the trick.

Of course, it might also be a bug but I just want to be sure.

@saeugetier
Copy link
Author

auth_api_key.lc : 512 bytes
espress.lc : 2456 bytes
http-200 : 12 bytes
http-400 : 20 bytes
http-401 : 21 bytes
http-403 : 18 bytes
http-404 : 19 bytes
http-405 : 27 bytes
http-503 : 28 bytes
http_not_found.lc : 280 bytes
http_request.lc : 600 bytes
http_response.lc : 568 bytes
http_response_send.lc : 584 bytes
http_response_sendfile.lc : 1244 bytes
init.lua : 454 bytes
router.lc : 856 bytes
routes/askme.post.lua : 336 bytes
routes/hello.get.lua : 135 bytes
routes_auto.lc : 728 bytes
server.lc : 176 bytes
server.lua : 257 bytes
static/hello.html : 910 bytes
type-css : 32 bytes
type-html : 33 bytes
type-ico : 21 bytes
type-jpg : 19 bytes
type-js : 39 bytes
type-json : 40 bytes
type-png : 18 bytes

@loicortola
Copy link
Owner

[Edit]
My bad. I misread your post. Seems there is a bug indeed. I'm trying to reproduce it.

@saeugetier
Copy link
Author

I think the bug is in file askme.post.lua

if req.params.question then
should be
if req.params["question"] not nil then

I seems that the code crashes if route is nil

@loicortola
Copy link
Owner

Both should work from my previous tests.
However, I think you are right for the route. If route does not exist, it will crash.
I will implement a safe behaviour tonight.
Can you work with that for now?

@loicortola
Copy link
Owner

Dear @saeugetier ,
I just released a new 0.3.0, with your fixes along with a lot of new improvements:
Changes:

  • Fixed body parsing bug
  • Fixed concurrent file reading bug
  • Added not_found as default behaviour
  • Added res:sendredirect method
  • Implemented global error handler
  • Implemented forms parsing
  • Added simple-website-with-forms sample
  • Added api with cjson sample
  • Added 500, 302 status codes to server default uploads
  • Updated docs and upload scripts

Thanks for helping with your issue, I hope you will like the new version.

N.B: There is a small API change when starting a server
Instead of

 espress:createserver(port)

 espress:use("plugin1.lc")
 -- ...

Write the following

 -- The server creation becomes lazy
 espress:createserver()

 espress:use("plugin1.lc")
 -- ...
 espress:listen(port)

@saeugetier
Copy link
Author

Thank you for the fast fix. I will try this version and report back.

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

2 participants