From 49b559f3c9bab0216bdab89ca96a034dd403dc75 Mon Sep 17 00:00:00 2001 From: TanninOne Date: Fri, 11 Nov 2016 10:27:18 +0100 Subject: [PATCH] Made reporting errors easier For the time being the about-button has been replaced with a "crash now" button to test and demonstrate error reporting. --- src/extensions/about_dialog/index.ts | 4 ++- src/util/errorHandling.ts | 52 +++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/extensions/about_dialog/index.ts b/src/extensions/about_dialog/index.ts index da1c84460..b2b15535d 100644 --- a/src/extensions/about_dialog/index.ts +++ b/src/extensions/about_dialog/index.ts @@ -1,7 +1,9 @@ import { IExtensionContext } from '../../types/IExtensionContext'; function init(context: IExtensionContext): boolean { - context.registerIcon('help-icons', 'question', 'About', () => alert('Hello World')); + context.registerIcon('help-icons', 'bomb', 'About', () => { + throw new Error('Test error reporting'); + }); return true; } diff --git a/src/util/errorHandling.ts b/src/util/errorHandling.ts index a38f4add2..4cd1be9dd 100644 --- a/src/util/errorHandling.ts +++ b/src/util/errorHandling.ts @@ -1,18 +1,49 @@ -import { app as appIn, dialog as dialogIn, remote } from 'electron'; +import { + app as appIn, + clipboard, + dialog as dialogIn, + remote, + shell, +} from 'electron'; -import { log } from './log'; +import {log} from './log'; export interface ITermination { message: string; details?: string; } +function createTitle(error: ITermination) { + return `Crash: ${error.message}`; +} + +function createReport(error: ITermination, config: any) { + return `### Application Crash +#### System +| | | +|------------ | -------------| +|Platform | ${process.platform}| +|Architecture | ${process.arch}| +|Application Version | ${config.version}| +#### Message +${error.message} +#### Details +\`\`\` +${error.details} +\`\`\` +#### Description + +`; +} + +declare var Notification: any; + /** * display an error message and quit the application * on confirmation. * Use this whenever the application state is unknown and thus * continuing could lead to data loss - * + * * @export * @param {ITermination} error */ @@ -22,14 +53,25 @@ export function terminate(error: ITermination) { log('error', 'unrecoverable error', error); - dialog.showMessageBox(null, { + let action = dialog.showMessageBox(null, { type: 'error', - buttons: [ 'Quit' ], + buttons: ['Report', 'Quit'], title: 'An unrecoverable error occured', message: error.message, detail: error.details, noLink: true, }); + if (action === 0) { + let config = require('../../package.json'); + clipboard.writeText(createReport(error, config)); + const title = encodeURIComponent(createTitle(error)); + const body = 'Please paste the content of your clipboard here and describe what you did ' + + 'when the crash happened.'; + let url = `${config.repository.url}/issues/new?title=${title}&labels[]=bug&body=${body}`; + log('info', 'create issue report', { url, len: body.length }); + // this assumes it's a github url + shell.openExternal(url); + } app.exit(1); }