Skip to content

Commit

Permalink
Made reporting errors easier
Browse files Browse the repository at this point in the history
For the time being the about-button has been replaced with a  "crash now" button to test and demonstrate error reporting.
  • Loading branch information
TanninOne committed Nov 11, 2016
1 parent 4aeac4e commit 49b559f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/extensions/about_dialog/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
52 changes: 47 additions & 5 deletions src/util/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -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
<Please describe what you were doing when the crash happened>
`;
}

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
*/
Expand All @@ -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);
}

0 comments on commit 49b559f

Please sign in to comment.