handleError.js 1.09 KiB
Newer Older
Amaury Martiny's avatar
Amaury Martiny committed
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
Amaury Martiny's avatar
Amaury Martiny committed
// SPDX-License-Identifier: BSD-3-Clause
import { app, dialog, shell } from 'electron';
Amaury Martiny's avatar
Amaury Martiny committed
import { bugs, name, parity } from '../../../package.json';
Amaury Martiny's avatar
Amaury Martiny committed
import Pino from './pino';
const logFile = `${app.getPath('userData')}/${name}.log`;
Amaury Martiny's avatar
Amaury Martiny committed
const pino = Pino();

export default (err, message = 'An error occurred.') => {
Amaury Martiny's avatar
Amaury Martiny committed
  pino.error(err);
Amaury Martiny's avatar
Amaury Martiny committed
  dialog.showMessageBox(
    {
      buttons: ['OK', 'Open logs'],
      defaultId: 0, // Default button id
      detail: `Please file an issue at ${
        bugs.url
      }. Please attach the following debugging info:
      
Amaury Martiny's avatar
Amaury Martiny committed
OS: ${process.platform}
Arch: ${process.arch}
Channel: ${parity.channel}
Amaury Martiny's avatar
Amaury Martiny committed
Error: ${err.message}

Please also attach the contents of the following file:
${logFile}.
Click on "Open logs" to open this file.`,
      message: `${message}`,
Amaury Martiny's avatar
Amaury Martiny committed
      title: 'Parity Error',
      type: 'error'
    },
    buttonId => {
      switch (buttonId) {
        case 1:
          shell.openItem(logFile);
          break;
        default:
          app.exit(1);
      }
    }