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 {boolean} critical the critical nature
|
||||
*/
|
||||
static error(ERROR_CODE, ERROR_MESSAGE, critical = true) {
|
||||
static error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) {
|
||||
(async () => {
|
||||
// Import the templating.
|
||||
const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default;
|
||||
|
||||
// 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) {
|
||||
alert(texts.localized(`error_msg_GUI`, null, [String(ERROR_CODE)]));
|
||||
alert(texts.localized(`error_msg_GUI`, false, [String(ERROR_CODE)]));
|
||||
} else {
|
||||
try {
|
||||
M.toast({ text: message });
|
||||
|
|
|
@ -18,57 +18,60 @@ export default class windowman {
|
|||
|
||||
// Prepare the window with its metadata.
|
||||
constructor() {
|
||||
function headers() {
|
||||
let LOAD_STATE = true;
|
||||
let UI = {
|
||||
CSS: [
|
||||
chrome.runtime.getURL(
|
||||
"gui/styles/external/fonts/materialdesignicons.min.css",
|
||||
),
|
||||
chrome.runtime.getURL(
|
||||
"gui/styles/external/materialize/css/materialize.css",
|
||||
),
|
||||
chrome.runtime.getURL("gui/styles/ui.css"),
|
||||
],
|
||||
};
|
||||
function headers() {
|
||||
let LOAD_STATE = true;
|
||||
let UI = {
|
||||
CSS: [
|
||||
chrome.runtime.getURL("gui/styles/external/fonts/materialdesignicons.min.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++) {
|
||||
const source = UI.CSS[index];
|
||||
for (let index = 0; index < UI[`CSS`].length; index++) {
|
||||
const source = UI.CSS[index];
|
||||
|
||||
(async () => {
|
||||
const net = await import(chrome.runtime.getURL(`/scripts/net.js`));
|
||||
try {
|
||||
(async () => {
|
||||
// Import source reading for later.
|
||||
const reader = (await import(chrome.runtime.getURL(`/gui/scripts/read.js`))).default;
|
||||
|
||||
const net = await import(chrome.runtime.getURL(`/scripts/net.js`));
|
||||
|
||||
let resource = false;
|
||||
try {
|
||||
resource = await net.download(source, `text`, true);
|
||||
} catch (err) {}
|
||||
let resource = false;
|
||||
try {
|
||||
resource = await net.download(source, `text`, true);
|
||||
} catch (err) {}
|
||||
|
||||
if (resource) {
|
||||
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 {
|
||||
const alerts = (
|
||||
await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))
|
||||
).default;
|
||||
const reader = (
|
||||
await import(chrome.runtime.getURL(`/gui/scripts/read.js`))
|
||||
).default;
|
||||
if (resource) {
|
||||
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`));
|
||||
}
|
||||
|
||||
})();
|
||||
} catch(err) {
|
||||
(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]);
|
||||
|
||||
alerts.error(-1, reader.localized(`error_msg_fileNotFound`), true, [
|
||||
source,
|
||||
]);
|
||||
|
||||
// Stop loading the page when an error has occured; it's not going to work!
|
||||
if (!DEBUG) {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
// 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.
|
||||
this[`metadata`] = chrome.windows.getCurrent();
|
||||
|
@ -453,11 +456,6 @@ export default class windowman {
|
|||
input_elements.forEach((input_element) => {
|
||||
if (input_element.getAttribute("data-enable")) {
|
||||
(async () => {
|
||||
console.log(
|
||||
await secretariat.read(
|
||||
input_element.getAttribute("data-enable"),
|
||||
),
|
||||
);
|
||||
input_element.disabled = !((await secretariat.read(
|
||||
input_element.getAttribute("data-enable"),
|
||||
)) != null
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
*/
|
||||
export async function download(URL, type, verify_only = false) {
|
||||
const alert = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))
|
||||
.default;
|
||||
const texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`)))
|
||||
.default;
|
||||
const alert = await import(chrome.runtime.getURL(`gui/scripts/alerts.js`))
|
||||
.default;
|
||||
const texts = (await import(chrome.runtime.getURL(`gui/scripts/read.js`)))
|
||||
.default;
|
||||
|
||||
let connect = await fetch(URL),
|
||||
data;
|
||||
let connect = await fetch(URL),
|
||||
data;
|
||||
|
||||
if (connect.ok && !verify_only) {
|
||||
data = await connect.text();
|
||||
if (connect.ok && !verify_only) {
|
||||
try {
|
||||
data = await connect.text();
|
||||
|
||||
if (
|
||||
type
|
||||
? type.toLowerCase().includes(`json`) || type.toLowerCase().includes(`dictionary`)
|
||||
: false
|
||||
) {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
// When not in JSON, run this.
|
||||
} catch(err) {
|
||||
throw new TypeError(texts.localized(`error_msg_notJSON`, false));
|
||||
};
|
||||
};
|
||||
} catch(err) {
|
||||
alert.error(err.name, err.message, err.stack);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
} catch (err) {
|
||||
if (
|
||||
type
|
||||
? type.toLowerCase().includes(`json`) ||
|
||||
type.toLowerCase().includes(`dictionary`)
|
||||
: false
|
||||
) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
alert.error(texts.localized(`error_msg_notJSON`, false));
|
||||
}
|
||||
}
|
||||
|
||||
// Return the filter.
|
||||
return verify_only ? connect.ok : data;
|
||||
// Return the filter.
|
||||
return verify_only ? connect.ok : data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue