mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1922506: Improve error handling. r=tjr
Improves error handling. We will have less (unexpected) errors. Differential Revision: https://phabricator.services.mozilla.com/D226186
This commit is contained in:
parent
f6b6704f9c
commit
6b52ba2fbc
@ -52,7 +52,10 @@ export class UserCharacteristicsCanvasRenderingChild extends JSWindowActorChild
|
||||
"Error getting canvas debug info during render: ",
|
||||
await stringifyError(e)
|
||||
);
|
||||
return { error: "COULD_NOT_GET_DEBUG_INFO", originalError: e };
|
||||
return {
|
||||
error: "COULD_NOT_GET_DEBUG_INFO",
|
||||
originalError: await stringifyError(e),
|
||||
};
|
||||
}
|
||||
|
||||
if (debugInfo.isAccelerated !== isAccelerated) {
|
||||
@ -66,10 +69,13 @@ export class UserCharacteristicsCanvasRenderingChild extends JSWindowActorChild
|
||||
await recipe.func(this.contentWindow, canvas, ctx);
|
||||
} catch (e) {
|
||||
lazy.console.error("Error rendering canvas: ", await stringifyError(e));
|
||||
return { error: "RENDERING_ERROR", originalError: e };
|
||||
return {
|
||||
error: "RENDERING_ERROR",
|
||||
originalError: await stringifyError(e),
|
||||
};
|
||||
}
|
||||
|
||||
return sha1(canvas.toDataURL("image/png", 1));
|
||||
return sha1(canvas.toDataURL("image/png", 1)).catch(stringifyError);
|
||||
};
|
||||
|
||||
const data = {
|
||||
|
@ -133,7 +133,7 @@ export class UserCharacteristicsWindowInfoChild extends JSWindowActorChild {
|
||||
didDestroy() {
|
||||
this.destroyed = true;
|
||||
for (const [type, handler] of Object.entries(this.handlers)) {
|
||||
this.contentWindow.windowRoot.removeEventListener(type, handler);
|
||||
this.contentWindow?.windowRoot?.removeEventListener(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,9 @@ export class UserCharacteristicsPageService {
|
||||
} finally {
|
||||
lazy.console.debug("Unregistering actors");
|
||||
this.cleanUp();
|
||||
lazy.console.debug("Cleanup done");
|
||||
this._backgroundBrowsers.delete(browser);
|
||||
lazy.console.debug("Background browser removed");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -131,6 +133,7 @@ export class UserCharacteristicsPageService {
|
||||
cleanUp() {
|
||||
ChromeUtils.unregisterWindowActor("UserCharacteristics");
|
||||
// unregisterWindowActor doesn't throw if the actor is not registered.
|
||||
// (Do note it console.error's but doesn't throw)
|
||||
// We can safely double unregister. We do this to handle the case where
|
||||
// the actor was registered but the function it was registered timed out.
|
||||
ChromeUtils.unregisterWindowActor("UserCharacteristicsWindowInfo");
|
||||
@ -244,10 +247,14 @@ export class UserCharacteristicsPageService {
|
||||
for (const win of Services.wm.getEnumerator("navigator:browser")) {
|
||||
if (!win.closed) {
|
||||
for (const tab of win.gBrowser.tabs) {
|
||||
const actor =
|
||||
const actor = await promiseTry(() =>
|
||||
tab.linkedBrowser.browsingContext?.currentWindowGlobal.getActor(
|
||||
"UserCharacteristicsWindowInfo"
|
||||
);
|
||||
)
|
||||
).catch(async e => {
|
||||
lazy.console.error("Error getting actor", e);
|
||||
this.handledErrors.push(await stringifyError(e));
|
||||
});
|
||||
|
||||
if (!actor) {
|
||||
continue;
|
||||
@ -897,3 +904,13 @@ function timeoutPromise(promise, ms) {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseTry(func) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(func());
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1062,7 +1062,7 @@ async function startPopulating() {
|
||||
for (const key in data) {
|
||||
try {
|
||||
output[key] = await data[key];
|
||||
debug(key, output[key].length);
|
||||
debug(key, output[key] ? output[key].length : "null");
|
||||
} catch (e) {
|
||||
debug("Promise rejected for", key, "Error:", e);
|
||||
errors.push(`${key}: ${await stringifyError(e)}`);
|
||||
|
Loading…
Reference in New Issue
Block a user