EvandroLG / pegasus.lua

:rocket: Pegasus.lua is an http server to work with web applications written in Lua language.
http://evandrolg.github.io/pegasus.lua/
MIT License
410 stars 36 forks source link

More descriptive crash message #106

Closed bbblitz closed 4 years ago

bbblitz commented 4 years ago

In some cases, server:accept() can fail, when it does it returns nil + an error message. When it fails, display the error instead of failing to index nil on the next line.

skwerlman commented 4 years ago

instead of raising an error here, would it make more sense to log a warning instead? that way a client connection error doesnt exit the main loop

EvandroLG commented 4 years ago

@skwerlman but if the error happened in server:accept(), how would handle this case? if you have a solution for it, can you show me how would be the code?

Thanks for the contribution @skwerlman and @bbblitz

bbblitz commented 4 years ago

@skwerlman but if the error happened in server:accept(), how would handle this case? if you have a solution for it, can you show me how would be the code?

I expect he means something like this:

local client, errmsg = server:accept()
if not client then
    print("Failed to accept connection:" .. errmsg)
end
...

And he's right, the web server really shouldn't crash in the middle of operation, @skwerlman do you want to make the PR or should I?

EvandroLG commented 4 years ago

@bbblitz could you update your PR with your last code? I'd love to merge this solution. Thanks a lot

Tieske commented 4 years ago

Maybe it should not be using print, but instead do:

io.stderr:write("Failed to accept connection:" .. errmsg .. "\n")
bbblitz commented 4 years ago

Huh, it automatically adds my commits instead of letting me clean them up first. Oh well.

EvandroLG commented 4 years ago

@bbblitz @skwerlman @Tieske fantastic guys! Thanks a lot!