Error handler that asks user to report crash

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
0x25a0
Prole
Posts: 36
Joined: Mon Mar 20, 2017 10:08 pm
Contact:

Error handler that asks user to report crash

Post by 0x25a0 »

Here's a little error handler that will ask the user to report a crash, either via e-mail or github.

Image

Clicking the email button opens a new email with email-address, error message, stacktrace, version and edition filled in:
Image

Clicking the GitHub button opens this page, again with all crash details filled in:
Image

If you want to use it in your project, all you need to do is fill in the details at the top of the function, and put it in your main.lua. Hopefully it will be obvious how to remove the github option if you don't need it, or replace it with the issue tracker of your choice.

I hope it's not inappropriate to post this here; it's by far not a full tool or library, but I wanted to share it to hear what you think about the approach, and I'm curious what other people do to collect crash reports.

A neat thing about this approach is that it gives you a way to get in touch with the user who reported the crash, either via the email-address they used or via their GitHub account. This is handy if you need more information to reproduce the crash, or simply if you want to thank them for reporting the crash.

I used this for my tool Quadtastic and received my first crash report today with a bug that I might have missed otherwise.

Code: Select all

function love.errhand(error_message)
  local app_name = "Supergame"
  local version = "game version"
  local github_url = "https://www.github.com/user/repo" -- no trailing slash
  local email = "your-email@provider.tld"
  local edition = love.system.getOS()

  local dialog_message = [[
%s crashed with the following error message:

%s

Would you like to report this crash so that it can be fixed?]]
  local titles = {"Oh no", "Oh boy", "Bad news"}
  local title = titles[love.math.random(#titles)]
  local full_error = debug.traceback(error_message or "")
  local message = string.format(dialog_message, app_name, full_error)
  local buttons = {"Yes, on GitHub", "Yes, by email", "No"}

  local pressedbutton = love.window.showMessageBox(title, message, buttons)

  local function url_encode(text)
    -- This is not complete. Depending on your issue text, you might need to
    -- expand it!
    text = string.gsub(text, "\n", "%%0A")
    text = string.gsub(text, " ", "%%20")
    text = string.gsub(text, "#", "%%23")
    return text
  end

  local issuebody = [[
%s crashed with the following error message:

%s

[If you can, describe what you've been doing when the error occurred]

---
Affects: %s
Edition: %s]]

  if pressedbutton == 1 then
    -- Surround traceback in ``` to get a Markdown code block
    full_error = table.concat({"```",full_error,"```"}, "\n")
    issuebody = string.format(issuebody, app_name, full_error, version, edition)
    issuebody = url_encode(issuebody)

    local subject = string.format("Crash in %s %s", app_name, version)
    local url = string.format("%s/issues/new?title=%s&body=%s",
                              github_url, subject, issuebody)
    love.system.openURL(url)
  elseif pressedbutton == 2 then
    issuebody = string.format(issuebody, app_name, full_error, version, edition)
    issuebody = url_encode(issuebody)

    local subject = string.format("Crash in %s %s", app_name, version)
    local url = string.format("mailto:%s?subject=%s&body=%s",
                              email, subject, issuebody)
    love.system.openURL(url)
  end
end
*edit* For the record, this code is released to the public domain. Knock yourself out :)

*edit 2* Forgot to mention that email and GitHub issues will already contain all necessary information
Last edited by 0x25a0 on Tue May 02, 2017 4:42 pm, edited 2 times in total.
User avatar
evölbug
Prole
Posts: 38
Joined: Wed Dec 21, 2016 12:58 pm
Contact:

Re: Error handler that asks user to report crash

Post by evölbug »

Oh hey, this looks quite useful! Never knew I wanted a custom handler until I saw this one :P
User avatar
peterrust
Prole
Posts: 42
Joined: Thu Dec 29, 2016 8:49 pm
Location: Bellingham, WA, USA
Contact:

Re: Error handler that asks user to report crash

Post by peterrust »

Very cool 0x25a0!

I would be interested in an error handler that automatically posts an error report to a server (say Firebase or a logging service like logEntries) and displays a screen to the user saying that it is reporting the bug and then that it successfully reported the bug when it's done... maybe that's a violation of privacy, it would probably require a license agreement at the beginning, something like "by playing this game, you agree to allow anonymous error reports to be sent", but worded a little less creepily.

I don't know about you, but I almost never click the report bug button when it comes up in various applications after a crash. But I appreciate it when an application tells me that the bug was reported and that someone will be working on it ASAP. I just don't want to have to do the "work" of filling out a bug report (even if it's just clicking a button, I'm always suspicious that there'll be a post-button follow-up form or something to complete).
User avatar
0x25a0
Prole
Posts: 36
Joined: Mon Mar 20, 2017 10:08 pm
Contact:

Re: Error handler that asks user to report crash

Post by 0x25a0 »

Thanks for the feedback, evölbug and peterrust!
I would be interested in an error handler that automatically posts an error report to a server
That was my initial plan, too. However, setting up a server and a logging service costs time and (possibly) money. I think sometimes it's nice to have something that "just works" out of the box.
But for larger projects I would totally agree that it's worth going the extra mile and setting up a logging system on a server.

*edit* As to how you would actually implement automatic crash reports: I never worked with Firebase or logEntries, but if there's an http-API that you can call to report crashes, then you could simply call that API at the beginning of the error handler, using luasocket which ships with Love. However, I'm not sure about https requests. As far as I know that's not exactly easy to do with Love atm...
I just don't want to have to do the "work" of filling out a bug report
I know what you mean :)
Maybe I should have mentioned that in the initial post, but when you click the email button, a template opens where the email-address, crash message, stack trace, version, and edition is already filled in:
Image
So, all the user has to do is send that email :)
The same happens when you press the GitHub button, but then of course all that information is filled out in a GitHub issue
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Error handler that asks user to report crash

Post by airstruck »

It is kind of nice to see exactly what's in the error report before it's sent, but I suspect you'd get more participation from automatic reports as peterrust suggests.

You should be able to send the email programatically, behind the scenes, not with the user's email account but just by connecting to your MX server and setting the sender to something that doesn't trigger spam filter. Might be tricky but should be possible (I've done stuff like this in the past, though not with Love/Lua).

Github is another story, I think you need HTTPS for all of their APIs.
User avatar
0x25a0
Prole
Posts: 36
Joined: Mon Mar 20, 2017 10:08 pm
Contact:

Re: Error handler that asks user to report crash

Post by 0x25a0 »

Thanks for the feedback, airstruck :)
but I suspect you'd get more participation from automatic reports as peterrust suggests.
Yeah.. I'm starting to believe you guys :D

Something else I didn't consider is that all the young kiddos some users might not even have an email client configured...
So while this might be an okay option for a tool, it seems like it's not such a great idea to use this in a game after all until it's more automated.
You should be able to send the email programatically, behind the scenes, not with the user's email account but just by connecting to your MX server and setting the sender to something that doesn't trigger spam filter. Might be tricky but should be possible (I've done stuff like this in the past, though not with Love/Lua).
Right, that could work. Thanks for the idea :)
Github is another story, I think you need HTTPS for all of their APIs.
Yes, that appears to be the case.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Error handler that asks user to report crash

Post by zorg »

Löve includes luasocket, that has methods for sending mail.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Error handler that asks user to report crash

Post by airstruck »

That's convenient, never noticed that.

The tricky part might be finding an email provider that still allows plain old SMTP connections. Some of the major ones only allow connections over TLS or other encryption, but I'm sure you can find one or two if you poke around (or set up your own, but it's a pain, web server would be much easier).
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Error handler that asks user to report crash

Post by yetneverdone »

Will that work also for the android port?

here's what ive done
1. Put all the "love.errhand" in a file called "error.lua"
2. used

Code: Select all

require("error")

function love.load()

end
3. Made a simple error-giving method

Code: Select all

function love.keypressed(key)
	if key == "p" then
		blah() --not existing function, should throw an error
	end
end
4. Instead of showing the error screen, the app just closes itself.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Error handler that asks user to report crash

Post by Nixola »

Can't you just include luasec for https (and possibly tls itself, I don't know)?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests