improve error handling
Make sure all errors are able to return their traces to be displayed, and that only the code appears in the pop-up, not a mix with the actual content.
This commit is contained in:
parent
76bf6cefaa
commit
e152034eeb
3 changed files with 81 additions and 79 deletions
|
@ -52,15 +52,15 @@ export default class alerts {
|
||||||
@param {number} ERROR_MESSAGE the custom error message
|
@param {number} ERROR_MESSAGE the custom error message
|
||||||
@param {boolean} critical the critical nature
|
@param {boolean} critical the critical nature
|
||||||
*/
|
*/
|
||||||
static error(ERROR_CODE, ERROR_MESSAGE, critical = true) {
|
static error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) {
|
||||||
(async () => {
|
(async () => {
|
||||||
// Import the templating.
|
// Import the templating.
|
||||||
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default;
|
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default;
|
||||||
|
|
||||||
// Display the error message.
|
// Display the error message.
|
||||||
console.error(texts.localized(`error_msg`, null, [ERROR_CODE, ERROR_MESSAGE]));
|
console.error(texts.localized(`error_msg`, false, [ERROR_CODE, ERROR_MESSAGE, ERROR_STACK]));
|
||||||
if (critical) {
|
if (critical) {
|
||||||
alert(texts.localized(`error_msg_GUI`, null, [String(ERROR_CODE)]));
|
alert(texts.localized(`error_msg_GUI`, false, [String(ERROR_CODE)]));
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
M.toast({ text: message });
|
M.toast({ text: message });
|
||||||
|
|
|
@ -18,57 +18,60 @@ export default class windowman {
|
||||||
|
|
||||||
// Prepare the window with its metadata.
|
// Prepare the window with its metadata.
|
||||||
constructor() {
|
constructor() {
|
||||||
function headers() {
|
function headers() {
|
||||||
let LOAD_STATE = true;
|
let LOAD_STATE = true;
|
||||||
let UI = {
|
let UI = {
|
||||||
CSS: [
|
CSS: [
|
||||||
chrome.runtime.getURL(
|
chrome.runtime.getURL("gui/styles/external/fonts/materialdesignicons.min.css"),
|
||||||
"gui/styles/external/fonts/materialdesignicons.min.css",
|
chrome.runtime.getURL("gui/styles/external/materialize/css/materialize.css"),
|
||||||
),
|
chrome.runtime.getURL("gui/styles/ui.css"),
|
||||||
chrome.runtime.getURL(
|
]
|
||||||
"gui/styles/external/materialize/css/materialize.css",
|
};
|
||||||
),
|
|
||||||
chrome.runtime.getURL("gui/styles/ui.css"),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let index = 0; index < UI[`CSS`].length; index++) {
|
for (let index = 0; index < UI[`CSS`].length; index++) {
|
||||||
const source = UI.CSS[index];
|
const source = UI.CSS[index];
|
||||||
|
|
||||||
(async () => {
|
try {
|
||||||
const net = await import(chrome.runtime.getURL(`/scripts/net.js`));
|
(async () => {
|
||||||
|
// Import source reading for later.
|
||||||
|
const reader = (await import(chrome.runtime.getURL(`/gui/scripts/read.js`))).default;
|
||||||
|
|
||||||
let resource = false;
|
const net = await import(chrome.runtime.getURL(`/scripts/net.js`));
|
||||||
try {
|
|
||||||
resource = await net.download(source, `text`, true);
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
if (resource) {
|
let resource = false;
|
||||||
let metadata_element = document.createElement(`link`);
|
try {
|
||||||
metadata_element.setAttribute(`rel`, `stylesheet`);
|
resource = await net.download(source, `text`, true);
|
||||||
metadata_element.setAttribute(`type`, `text/css`);
|
} catch (err) {}
|
||||||
metadata_element.setAttribute(`href`, source);
|
|
||||||
document.querySelector(`head`).appendChild(metadata_element);
|
|
||||||
} else {
|
|
||||||
const alerts = (
|
|
||||||
await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))
|
|
||||||
).default;
|
|
||||||
const reader = (
|
|
||||||
await import(chrome.runtime.getURL(`/gui/scripts/read.js`))
|
|
||||||
).default;
|
|
||||||
|
|
||||||
alerts.error(-1, reader.localized(`error_msg_fileNotFound`), true, [
|
if (resource) {
|
||||||
source,
|
let metadata_element = document.createElement(`link`);
|
||||||
]);
|
metadata_element.setAttribute(`rel`, `stylesheet`);
|
||||||
|
metadata_element.setAttribute(`type`, `text/css`);
|
||||||
|
metadata_element.setAttribute(`href`, source);
|
||||||
|
document.querySelector(`head`).appendChild(metadata_element);
|
||||||
|
} else {
|
||||||
|
throw new ReferenceError(reader.localized(`error_msg_fileNotFound`));
|
||||||
|
}
|
||||||
|
|
||||||
// Stop loading the page when an error has occured; it's not going to work!
|
})();
|
||||||
if (!DEBUG) {
|
} catch(err) {
|
||||||
window.close();
|
(async() => {
|
||||||
}
|
const alerts = (await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))).default;
|
||||||
}
|
|
||||||
})();
|
// Raise an alert.
|
||||||
}
|
alerts.error(err.name, err.message, err.stack, true, [source]);
|
||||||
}
|
|
||||||
|
// Stop loading the page when an error has occured; it's not going to work!
|
||||||
|
if (!DEBUG) {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Stop loading immediately during the error.
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the window.
|
// Get the window.
|
||||||
this[`metadata`] = chrome.windows.getCurrent();
|
this[`metadata`] = chrome.windows.getCurrent();
|
||||||
|
@ -453,11 +456,6 @@ export default class windowman {
|
||||||
input_elements.forEach((input_element) => {
|
input_elements.forEach((input_element) => {
|
||||||
if (input_element.getAttribute("data-enable")) {
|
if (input_element.getAttribute("data-enable")) {
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log(
|
|
||||||
await secretariat.read(
|
|
||||||
input_element.getAttribute("data-enable"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
input_element.disabled = !((await secretariat.read(
|
input_element.disabled = !((await secretariat.read(
|
||||||
input_element.getAttribute("data-enable"),
|
input_element.getAttribute("data-enable"),
|
||||||
)) != null
|
)) != null
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* net.js
|
/* net.js
|
||||||
This script provides network utilities.
|
This script provides network utilities.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -11,31 +11,35 @@ Download a file from the network or locally.
|
||||||
@returns {Promise} the downloaded file
|
@returns {Promise} the downloaded file
|
||||||
*/
|
*/
|
||||||
export async function download(URL, type, verify_only = false) {
|
export async function download(URL, type, verify_only = false) {
|
||||||
const alert = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))
|
const alert = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))
|
||||||
.default;
|
.default;
|
||||||
const texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`)))
|
const texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`)))
|
||||||
.default;
|
.default;
|
||||||
|
|
||||||
let connect = await fetch(URL),
|
let connect = await fetch(URL),
|
||||||
data;
|
data;
|
||||||
|
|
||||||
if (connect.ok && !verify_only) {
|
if (connect.ok && !verify_only) {
|
||||||
data = await connect.text();
|
try {
|
||||||
|
data = await connect.text();
|
||||||
|
|
||||||
try {
|
if (
|
||||||
} catch (err) {
|
type
|
||||||
if (
|
? type.toLowerCase().includes(`json`) || type.toLowerCase().includes(`dictionary`)
|
||||||
type
|
: false
|
||||||
? type.toLowerCase().includes(`json`) ||
|
) {
|
||||||
type.toLowerCase().includes(`dictionary`)
|
try {
|
||||||
: false
|
data = JSON.parse(data);
|
||||||
) {
|
// When not in JSON, run this.
|
||||||
data = JSON.parse(data);
|
} catch(err) {
|
||||||
}
|
throw new TypeError(texts.localized(`error_msg_notJSON`, false));
|
||||||
alert.error(texts.localized(`error_msg_notJSON`, false));
|
};
|
||||||
}
|
};
|
||||||
}
|
} catch(err) {
|
||||||
|
alert.error(err.name, err.message, err.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return the filter.
|
// Return the filter.
|
||||||
return verify_only ? connect.ok : data;
|
return verify_only ? connect.ok : data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue