moved global_errors.js to ts
parent
f433acda77
commit
9f3379e702
@ -1,11 +0,0 @@
|
||||
export interface BaseConfig {
|
||||
set(keyPath: string, value: any): void;
|
||||
get(keyPath: string): any | undefined;
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
allowMalformedOnStartup: boolean;
|
||||
}
|
||||
|
||||
export function start(name: string, targetPath: string, options: Options): BaseConfig;
|
@ -1,50 +0,0 @@
|
||||
const electron = require('electron');
|
||||
|
||||
const { app, dialog, clipboard } = electron;
|
||||
const { redactAll } = require('../ts/util/privacy');
|
||||
|
||||
// We use hard-coded strings until we're able to update these strings from the locale.
|
||||
let quitText = 'Quit';
|
||||
let copyErrorAndQuitText = 'Copy error and quit';
|
||||
|
||||
function handleError(prefix, error) {
|
||||
if (console._error) {
|
||||
console._error(`${prefix}:`, error);
|
||||
}
|
||||
console.error(`${prefix}:`, error);
|
||||
|
||||
if (app.isReady()) {
|
||||
// title field is not shown on macOS, so we don't use it
|
||||
const buttonIndex = dialog.showMessageBox({
|
||||
buttons: [quitText, copyErrorAndQuitText],
|
||||
defaultId: 0,
|
||||
detail: redactAll(error.stack),
|
||||
message: prefix,
|
||||
noLink: true,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
if (buttonIndex === 1) {
|
||||
clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`);
|
||||
}
|
||||
} else {
|
||||
dialog.showErrorBox(prefix, error.stack);
|
||||
}
|
||||
|
||||
app.exit(1);
|
||||
}
|
||||
|
||||
exports.updateLocale = messages => {
|
||||
quitText = messages.quit;
|
||||
copyErrorAndQuitText = messages.copyErrorAndQuit;
|
||||
};
|
||||
|
||||
exports.addHandler = () => {
|
||||
process.on('uncaughtException', error => {
|
||||
handleError('Unhandled Error', error);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
handleError('Unhandled Promise Rejection', error);
|
||||
});
|
||||
};
|
@ -0,0 +1,51 @@
|
||||
import { app, clipboard, dialog } from 'electron';
|
||||
import { redactAll } from '../util/privacy';
|
||||
import { LocaleMessagesType } from './locale';
|
||||
import { ConsoleCustom } from './logging';
|
||||
// tslint:disable: no-console
|
||||
|
||||
// We use hard-coded strings until we're able to update these strings from the locale.
|
||||
let quitText = 'Quit';
|
||||
let copyErrorAndQuitText = 'Copy error and quit';
|
||||
|
||||
async function handleError(prefix: string, error: any) {
|
||||
if ((console as ConsoleCustom)._error) {
|
||||
(console as ConsoleCustom)._error(`${prefix}:`, error);
|
||||
}
|
||||
console.error(`${prefix}:`, error);
|
||||
|
||||
if (app.isReady()) {
|
||||
// title field is not shown on macOS, so we don't use it
|
||||
const button = await dialog.showMessageBox({
|
||||
buttons: [quitText, copyErrorAndQuitText],
|
||||
defaultId: 0,
|
||||
detail: redactAll(error.stack),
|
||||
message: prefix,
|
||||
noLink: true,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
if (button.response === 1) {
|
||||
clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`);
|
||||
}
|
||||
} else {
|
||||
dialog.showErrorBox(prefix, error.stack);
|
||||
}
|
||||
|
||||
app.exit(1);
|
||||
}
|
||||
|
||||
export const updateLocale = (messages: LocaleMessagesType) => {
|
||||
quitText = messages.quit;
|
||||
copyErrorAndQuitText = messages.copyErrorAndQuit;
|
||||
};
|
||||
|
||||
export const addHandler = () => {
|
||||
process.on('uncaughtException', async error => {
|
||||
await handleError('Unhandled Error', error);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', async error => {
|
||||
await handleError('Unhandled Promise Rejection', error);
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue