Page 2 of 3

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 2:56 pm
by 0x25a0
yetneverdone wrote: Wed May 03, 2017 2:47 am Will that work also for the android port?
It seems to work on Android, too, but doesn't look very nice. You could remove the stack trace from the displayed message to make it more readable. But other than that it works as expected; the email button for example opens the default email app with the same draft that you'd get on desktop.
yetneverdone wrote: Wed May 03, 2017 2:47 am Instead of showing the error screen, the app just closes itself.
yetneverdone, could you check if it works for you with the attached .love archive? Maybe you could use that as a starting point. I'm not sure what could be wrong with your approach though.
Nixola wrote: Wed May 03, 2017 5:43 am Can't you just include luasec for https (and possibly tls itself, I don't know)?
Just to clarify, in that case you'd need to ship luasec as a pre-compiled shared library for each platform?
Or is there an easier way?
zorg wrote: Tue May 02, 2017 11:47 pm Löve includes luasocket, that has methods for sending mail.
Thanks for the hint, zorg :)
I tinkered around with that and got it to work.
airstruck wrote: Wed May 03, 2017 12:22 am The tricky part might be finding an email provider that still allows plain old SMTP connections.
Yup. I couldn't get it to work via gmail's smtp server for example (presumably because it enforces TLS).
However, I've also tried it with my uberspace account, and that worked.

But that's not all.
As far as I know you'll have to authenticate to any public smtp server if you want it to accept your email.
So you'd have to include those credentials in your source code, which is a path I'm not willing to take.
*edit* as airstruck points out below, the smtp server might deliver emails even without authentication

So for the record, with the code below it does work if the SMTP server doesn't enforce TLS.
You'll need to adjust 'to', 'server', and possibly the port.

Code: Select all

local smtp = require("socket.smtp")
local ltn12 = require("ltn12")

local from = "no-reply@domain.com"
local to   = "crashreport@domain.com"
local headers = { to      = to,
                  from    = from,
                  subject = "This is a test",
                }
local source = smtp.message({ headers = headers,
                              body    = "Hello World!",
                            })

local r, err = smtp.send({ source   = source,
                           from     = from,
                           rcpt     = to,
                           server   = "server",
                           port     = 587,
                         })

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 3:06 pm
by yetneverdone
yetneverdone, could you check if it works for you with the attached .love archive? Maybe you could use that as a starting point. I'm not sure what could be wrong with your approach though.
It seems that the "error("foobar")" function is the only difference in our codes.

I even tried putting the whole love.errhand function in the main.lua file

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 3:27 pm
by 0x25a0
yetneverdone wrote: Wed May 03, 2017 3:06 pm It seems that the "error("foobar")" function is the only difference in our codes.
I even tried putting the whole love.errhand function in the main.lua file
So the app still just closes and you don't see a dialog? Hmm that's odd.
If you could upload your .love archive, I could have a look and see if I can spot any problems.

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 3:57 pm
by yetneverdone
0x25a0 wrote: Wed May 03, 2017 3:27 pm
yetneverdone wrote: Wed May 03, 2017 3:06 pm It seems that the "error("foobar")" function is the only difference in our codes.
I even tried putting the whole love.errhand function in the main.lua file
So the app still just closes and you don't see a dialog? Hmm that's odd.
If you could upload your .love archive, I could have a look and see if I can spot any problems.
Yes it does.
I will tell you the password for the archive in a message.

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 7:59 pm
by airstruck
0x25a0 wrote:As far as I know you'll have to authenticate to any public smtp server if you want it to accept your email.
That shouldn't be the case; after all I can send email from my gmail to your uberspace without knowing your password (and without gmail knowing it). It's been a few years since I've looked at this and I can't remember the details, unfortunately.

Here are a couple of links that might help:

http://stackoverflow.com/a/29828911
https://luxsci.com/blog/how-to-send-unl ... r-ssl.html

Re: Error handler that asks user to report crash

Posted: Wed May 03, 2017 8:52 pm
by 0x25a0
Oh wow, it does work without authentication :-O
Thanks a lot, airstruck!

With that out of the way it should be possible to fully automate the crash reporting. I'll add an example to the original post when I find the time.

Re: Error handler that asks user to report crash

Posted: Thu May 04, 2017 6:12 am
by adnzzzzZ
Nice dude, really cool.

I saw that you mentioned how setting up a server would be costly or something like that, but there are services like GCP https://cloud.google.com/free/ that give you free access as long as you don't go over a certain usage limit. It's perfect for testing small stuff like this to see that it actually works and I've used it successfully to have players automatically send data to my server. Then if you decide to do it for real you can move to a normal paid plan.

Re: Error handler that asks user to report crash

Posted: Thu May 04, 2017 9:05 am
by bartbes
0x25a0 wrote: Wed May 03, 2017 8:52 pm Oh wow, it does work without authentication :-O
Thanks a lot, airstruck!
If you contact the receiver's mail server directly it should accept their mail, because that's how delivery works. The problem, of course, is that you're then delivering mail from what is likely to be a residential ip, without SPF, DKIM or DMARC set up, so you might want to check your spam folder regularly, or filter these mails specifically. And then there might be some firewalls that block these connections, so make sure it fails gracefully if you can't connect or deliver. It could work, but it's likely easier to set up a web page you can just POST the message to.

Re: Error handler that asks user to report crash

Posted: Thu May 04, 2017 1:32 pm
by airstruck
bartbes wrote:It could work, but it's likely easier to set up a web page you can just POST the message to.
That might be easier if you already have a web server set up, with a domain pointed at it, and a database installed. Then you just need a script to accept the posts and store them, and a script to view them, and a script to install everything and set up the database schema and so on. And maybe a script to email you a notification, too...

Setting all that stuff up for the first time (and writing those scripts, if they don't ship with the library) will almost certainly not be easier than signing up for a free email account, adding a forwarding rule or filter, and configuring the crash handler with an email address and MX server. Might be more reliable, though (or not, depending on who set up the web server and scripted everything, and how well email providers behave).

I wouldn't worry about SPF and DKIM, either it works reliably with a given email service or it doesn't, you can expect the user will want to filter/forward it anyway, so it would just be a matter of recommending a few email services that are known to work. Firewall could be an occasional issue, but it's no different for web traffic with software firewalls that block unknown programs.

Re: Error handler that asks user to report crash

Posted: Tue May 09, 2017 4:08 pm
by 0x25a0
Thanks, adnzzzzZ!
adnzzzzZ wrote: Thu May 04, 2017 6:12 am there are services like GCP https://cloud.google.com/free/ that give you free access as long as you don't go over a certain usage limit
Good point, it's worth mentioning that these exist :) AWS also has a free tier https://aws.amazon.com/free/
airstruck wrote: Thu May 04, 2017 1:32 pm
bartbes wrote:It could work, but it's likely easier to set up a web page you can just POST the message to.
That might be easier if you already have a web server set up, with a domain pointed at it, and a database installed. [...]

Setting all that stuff up for the first time (and writing those scripts, if they don't ship with the library) will almost certainly not be easier than signing up for a free email account, adding a forwarding rule or filter, and configuring the crash handler with an email address and MX server.
I agree with airstruck here. It's true that the stuff you'd need to set up isn't very complex, but you do need the infrastructure, you do need some basic knowledge about how to set up a database and a little web server that accepts your crash reports and so on. These things add up, and all of the sudden you spend days worrying about this stuff instead of working on your game.

It would be great if someone wrote a library that solved all of these problems, and for larger projects I totally agree that you're probably better off writing your own little server that you can tweak to your needs. But I do think that the email approach has its place. What I find very powerful about Love is how easy it is to get started. It just takes a few lines of code to draw something, and after a few more lines you can move that thing with WASD. The learning curve is very shallow, what makes it approachable to newcomers. If there is a reliable way to submit crash reports via email, then this would fall in line with that paradigm; all you'd need to collect crash reports is an email address.

So, I went ahead and extracted the error handler code into a separate module, crush. Its API consists of these functions (and a few others that are less interesting):

Code: Select all

function crush.report_automatically(error_message, recipient, smtp_config, extra_info, stack_offset)
tries to automatically submit the crash report to the given recipient via email, using the server and port provided in smtp_config. extra_info (optional) is a key-value table containing any additional information you want to include (e.g. version, operating system, current level etc), and stack_offset (optional) can be used to skip some items of the traceback (like love.errhand).

Code: Select all

function crush.report_manually(error_message, recipient, extra_info, stack_offset)
asks the user to submit the crash report manually (using the mailto URL). All arguments have the same meaning as in report_automatically.

You can also attach files (e.g. a log file) when using the automatic report (As far as I know that's not possible with the mailto URL).

If the automatic report fails, it will ask the user to submit the report manually.

Here is how you'd use it:

Code: Select all

local crush = require("crush")

function love.draw() love.graphics.print("Click to provoke an error") end

function love.mousepressed() error("intended crash") end

function love.errhand(error_message)
  crush.pcall(function() -- Wrap your error handling code in crush.pcall for extra protection.
    local recipient = "your@email.com"
    local smtp_config = {server = "server.com", port = 587}
    local extra_info = {
      Version = "0.8.3-rc1",
      OS = love.system.getOS(),
      _files = { -- special key for file attachments
        "some/file.jpg",
        {
          mimetype = "text/plain",
          filename = "another/file.txt"
        }
      }
    }
    crush.report_automatically(error_message, recipient, smtp_config, extra_info, 3)
    -- crush.report_manually(error_message, recipient, extra_info, 3)
  end)
end
I wouldn't worry about SPF and DKIM, either it works reliably with a given email service or it doesn't, you can expect the user will want to filter/forward it anyway, so it would just be a matter of recommending a few email services that are known to work.
I did get it to work via gmail, surprisingly. Google has different SMTP servers for different scenarios (https://support.google.com/a/answer/176600?hl=en), and aspmx.l.google.com doesn't require TLS. So, if you use "<your.address@gmail.com>" (the angular brackets are necessary) as recipient, and "aspmx.l.google.com" as server on port 25, then it should work.

I'd be super grateful if a few people could verify from their computer that this works. Maybe it does turn out to be unreliable or inconsistent.

Unfortunately I had no luck with any of the traditional email providers (so far I tried yahoo.com, mail.com and gmx.net), but maybe I just didn't test the right settings. My IP was also temporarily blacklisted (probably because I tinkered around too much with servers and ports and so on), which also caused gmail to drop some of my requests. I was able to send again a few hours later though, and I haven't had any problems since then.

I've attached two files, crush.lua contains only the crush module, and crush-test.love is basically the usage example above. You will need to change the recipient email address in main.lua to try it out. If you're asked to submit the crash report manually, then the automatic submission failed. This is the fallback method I mentioned above. You can check the console for the error message to see why it failed.