mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 13:18:40 -09:00
Adding ability to send error object to notify() (#2955)
This commit is contained in:
parent
4aedb6b9a0
commit
32626bd2ab
6 changed files with 39 additions and 35 deletions
|
|
@ -15,9 +15,7 @@ const _syntaxValidation = function(cfg) {
|
||||||
try {
|
try {
|
||||||
return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true});
|
return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notify('Error loading config:', `${err.name}, see DevTools for more info`);
|
notify('Error loading config:', `${err.name}, see DevTools for more info`, {error: err});
|
||||||
//eslint-disable-next-line no-console
|
|
||||||
console.error('Error loading config:', err);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,13 @@ app.on('ready', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function notify(title, body) {
|
function notify(title, body, details = {}) {
|
||||||
//eslint-disable-next-line no-console
|
//eslint-disable-next-line no-console
|
||||||
console.log(`[Notification] ${title}: ${body}`);
|
console.log(`[Notification] ${title}: ${body}`);
|
||||||
|
if (details.error) {
|
||||||
|
//eslint-disable-next-line no-console
|
||||||
|
console.error(details.error);
|
||||||
|
}
|
||||||
if (win) {
|
if (win) {
|
||||||
win.webContents.send('notification', {title, body});
|
win.webContents.send('notification', {title, body});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ function updatePlugins({force = false} = {}) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
//eslint-disable-next-line no-console
|
//eslint-disable-next-line no-console
|
||||||
notify('Error updating plugins.', err);
|
notify('Error updating plugins.', err, {error: err});
|
||||||
} else {
|
} else {
|
||||||
// flag successful plugin update
|
// flag successful plugin update
|
||||||
cache.set('hyper.plugins', id_);
|
cache.set('hyper.plugins', id_);
|
||||||
|
|
@ -257,9 +257,7 @@ function requirePlugins() {
|
||||||
//eslint-disable-next-line no-console
|
//eslint-disable-next-line no-console
|
||||||
console.warn(`Plugin "${basename(path_)}" not found: ${path_}`);
|
console.warn(`Plugin "${basename(path_)}" not found: ${path_}`);
|
||||||
} else {
|
} else {
|
||||||
//eslint-disable-next-line no-console
|
notify('Plugin error!', `Plugin "${basename(path_)}" failed to load (${err.message})`, {error: err});
|
||||||
console.error(err);
|
|
||||||
notify('Plugin error!', `Plugin "${basename(path_)}" failed to load (${err.message})`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -276,7 +274,9 @@ exports.onApp = app_ => {
|
||||||
try {
|
try {
|
||||||
plugin.onApp(app_);
|
plugin.onApp(app_);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`);
|
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`, {
|
||||||
|
error: e
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -288,7 +288,9 @@ exports.onWindow = win => {
|
||||||
try {
|
try {
|
||||||
plugin.onWindow(win);
|
plugin.onWindow(win);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`);
|
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`, {
|
||||||
|
error: e
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -304,7 +306,7 @@ function decorateObject(base, key) {
|
||||||
try {
|
try {
|
||||||
res = plugin[key](decorated);
|
res = plugin[key](decorated);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify('Plugin error!', `"${plugin._name}" when decorating ${key}`);
|
notify('Plugin error!', `"${plugin._name}" when decorating ${key}`, {error: e});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (res && typeof res === 'object') {
|
if (res && typeof res === 'object') {
|
||||||
|
|
@ -330,7 +332,9 @@ exports.getDeprecatedConfig = () => {
|
||||||
try {
|
try {
|
||||||
configTmp = plugin.decorateConfig(JSON.parse(JSON.stringify(baseConfig)));
|
configTmp = plugin.decorateConfig(JSON.parse(JSON.stringify(baseConfig)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`);
|
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`, {
|
||||||
|
error: e
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const pluginCSSDeprecated = config.getDeprecatedCSS(configTmp);
|
const pluginCSSDeprecated = config.getDeprecatedCSS(configTmp);
|
||||||
|
|
|
||||||
|
|
@ -258,9 +258,7 @@ export function openFile(path) {
|
||||||
effect() {
|
effect() {
|
||||||
stat(path, (err, stats) => {
|
stat(path, (err, stats) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
//eslint-disable-next-line no-console
|
notify('Unable to open path', `"${path}" doesn't exist.`, {error: err});
|
||||||
console.error(err.stack);
|
|
||||||
notify('Unable to open path', `"${path}" doesn't exist.`);
|
|
||||||
} else {
|
} else {
|
||||||
let command = escapeShellCmd(path).replace(/ /g, '\\ ');
|
let command = escapeShellCmd(path).replace(/ /g, '\\ ');
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
/* global Notification */
|
/* global Notification */
|
||||||
/* eslint no-new:0 */
|
/* eslint no-new:0 */
|
||||||
export default function notify(title, body) {
|
export default function notify(title, body, details = {}) {
|
||||||
//eslint-disable-next-line no-console
|
//eslint-disable-next-line no-console
|
||||||
console.log(`[Notification] ${title}: ${body}`);
|
console.log(`[Notification] ${title}: ${body}`);
|
||||||
|
if (details.error) {
|
||||||
|
//eslint-disable-next-line no-console
|
||||||
|
console.error(details.error);
|
||||||
|
}
|
||||||
new Notification(title, {body});
|
new Notification(title, {body});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,11 +137,10 @@ const loadModules = () => {
|
||||||
try {
|
try {
|
||||||
mod = window.require(path);
|
mod = window.require(path);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
|
||||||
console.error(err.stack);
|
|
||||||
notify(
|
notify(
|
||||||
'Plugin load error',
|
'Plugin load error',
|
||||||
`"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`
|
`"${pluginName}" failed to load in the renderer process. Check Developer Tools for details.`,
|
||||||
|
{error: err}
|
||||||
);
|
);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
@ -276,9 +275,9 @@ function getProps(name, props, ...fnArgs) {
|
||||||
try {
|
try {
|
||||||
ret_ = fn(...fnArgs, props_);
|
ret_ = fn(...fnArgs, props_);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
|
||||||
console.error(err.stack);
|
error: err
|
||||||
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`);
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,11 +322,10 @@ export function connect(stateFn, dispatchFn, c, d = {}) {
|
||||||
try {
|
try {
|
||||||
ret_ = fn(state, ret);
|
ret_ = fn(state, ret);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
|
||||||
console.error(err.stack);
|
|
||||||
notify(
|
notify(
|
||||||
'Plugin error',
|
'Plugin error',
|
||||||
`${fn._pluginName}: Error occurred in \`map${name}State\`. Check Developer Tools for details.`
|
`${fn._pluginName}: Error occurred in \`map${name}State\`. Check Developer Tools for details.`,
|
||||||
|
{error: err}
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -349,11 +347,10 @@ export function connect(stateFn, dispatchFn, c, d = {}) {
|
||||||
try {
|
try {
|
||||||
ret_ = fn(dispatch, ret);
|
ret_ = fn(dispatch, ret);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
|
||||||
console.error(err.stack);
|
|
||||||
notify(
|
notify(
|
||||||
'Plugin error',
|
'Plugin error',
|
||||||
`${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`
|
`${fn._pluginName}: Error occurred in \`map${name}Dispatch\`. Check Developer Tools for details.`,
|
||||||
|
{error: err}
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -387,9 +384,9 @@ function decorateReducer(name, fn) {
|
||||||
try {
|
try {
|
||||||
state__ = pluginReducer(state_, action);
|
state__ = pluginReducer(state_, action);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
|
||||||
console.error(err.stack);
|
error: err
|
||||||
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`);
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -436,7 +433,7 @@ function exposeDecorated(Component_) {
|
||||||
try {
|
try {
|
||||||
this.props.onDecorated(decorated_);
|
this.props.onDecorated(decorated_);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify('Plugin error', `Error occurred. Check Developer Tools for details`);
|
notify('Plugin error', `Error occurred. Check Developer Tools for details`, {error: e});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -462,11 +459,10 @@ function getDecorated(parent, name) {
|
||||||
class__ = fn(class_, {React, PureComponent, Notification, notify});
|
class__ = fn(class_, {React, PureComponent, Notification, notify});
|
||||||
class__.displayName = `${fn._pluginName}(${name})`;
|
class__.displayName = `${fn._pluginName}(${name})`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
//eslint-disable-next-line no-console
|
|
||||||
console.error(err.stack);
|
|
||||||
notify(
|
notify(
|
||||||
'Plugin error',
|
'Plugin error',
|
||||||
`${fn._pluginName}: Error occurred in \`${method}\`. Check Developer Tools for details`
|
`${fn._pluginName}: Error occurred in \`${method}\`. Check Developer Tools for details`,
|
||||||
|
{error: err}
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue