Bug 1837075 - Never throw from NativeManifests's _tryPath r=willdurand

Callers of _tryPath (specifically of NativeManifests.lookupManifest) do
not expect any errors, and they are not prepared to handle it well,
because the expectation is to either return the requested manifest,
or to return null + error being logged.

The previous implementation could raise uncaught errors, e.g. encoding
errors (covered by tests), file access denied, etc. External files
should not be able to confuse the internal implementation, so we
log the error instead of printing.

Now, the only way for errors to be thrown is if there is an actual bug
with the internal implementation.

Differential Revision: https://phabricator.services.mozilla.com/D180149
This commit is contained in:
Rob Wu 2023-07-13 13:13:29 +00:00
parent ec91b25e02
commit e39b0c81fd
2 changed files with 9 additions and 11 deletions

View File

@ -106,7 +106,8 @@ export var NativeManifests = {
}
return null;
}
throw ex;
Cu.reportError(ex);
return null;
}
let normalized = lazy.Schemas.normalize(
manifest,

View File

@ -308,17 +308,14 @@ add_task(async function test_manifest_with_invalid_utf_8() {
USER_TEST_JSON
);
}
// Note: most content failures (malformed JSON, etc.) do not result in a
// rejection, but in the manifest file being ignored (and on non-Windows:
// looking for manifests in the next location).
//
// It is inconsistent to reject instead of be returning null here, but that
// behavior seems long-standing in Firefox.
await Assert.rejects(
lookupApplication("test", context),
/NotReadableError: Could not read file.* because it is not UTF-8 encoded/,
"lookupApplication should reject file with invalid UTF8"
let { messages, result } = await promiseConsoleOutput(() =>
lookupApplication("test", context)
);
equal(result, null, "lookupApplication should reject file with invalid UTF8");
let errorPattern =
/NotReadableError: Could not read file.* because it is not UTF-8 encoded/;
let utf8Errors = messages.filter(({ message }) => errorPattern.test(message));
equal(utf8Errors.length, 1, "lookupApplication logs error about UTF-8");
});
add_task(async function test_invalid_json() {