Skip to content

Commit

Permalink
Add more friendly error message dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Oct 1, 2018
1 parent ee24239 commit 1d53c0a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
38 changes: 38 additions & 0 deletions app/browser/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import process from 'process'
import os from 'os'
import { dialog, clipboard } from 'electron'
import { PRODUCT_NAME } from 'constants/app'

const isNativeDllError = (err: Error) =>
os.platform() === 'win32' &&
err.message.indexOf('The specified module could not be found') > -1 &&
err.message.indexOf('dlopen') > -1

process.on('uncaughtException', err => {
const message = err.stack || err.message || 'Unknown error'
if (isNativeDllError(err)) {
dialog.showErrorBox(
'Error: Missing native dependency',
`Please install 'Visual C++ Redistributable for Visual Studio 2015' to continue.
${message}`
)
} else {
const reportUrl = 'https://github.com/samuelmaddock/metastream/issues'

console.error(message)
clipboard.writeText(`${reportUrl}\n${message}`)

dialog.showErrorBox(
`${PRODUCT_NAME} Error`,
`An error occurred while running ${PRODUCT_NAME}. The program will terminate after closing this message.
Please report this issue to the developer by creating an issue on GitHub. The full error message has been copied to your clipboard.
${reportUrl}
${message}`
)
}

process.exit(1)
})
13 changes: 4 additions & 9 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/**
* This module executes inside of electron's main process. You can start
* electron renderer process from here and communicate with the other processes
* through IPC.
*
* When running `npm run build` or `npm run build-main`, this file is compiled to
* `./app/main.prod.js` using webpack. This gives us some performance wins.
*/
import { app, BrowserWindow, globalShortcut, protocol } from 'electron'
// Error handling
import 'browser/error'

import { app, BrowserWindow, globalShortcut } from 'electron'
import { PRODUCT_NAME, VERSION } from 'constants/app'

if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true') {
Expand Down

0 comments on commit 1d53c0a

Please sign in to comment.