Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_packager.py: Handle failure to get cached package #21328

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ def generate_js(data_target, data_files, metadata):
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
var getRequest = packages.get(`package/${packageName}/${chunkId}`);
getRequest.onsuccess = function(event) {
if (!event.target.result) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the onsuccess callback be triggered in this case?

Copy link
Contributor Author

@past-due past-due Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why it's implemented that way in IDBObjectStore, but that seems to be how it works.

According to https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/get :

This method produces the same result for: a) a record that doesn't exist in the database and b) a record that has an undefined value.

Of note: The earlier implementation in checkCachedPackage() does already handle this case:

getRequest.onsuccess = function(event) {
var result = event.target.result;
if (!result) {
return callback(false, null);

The handling is just missing in fetchCachedPackage(), which this PR adds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so when a record is not found that is not an error but a success with an empty result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so when a record is not found that is not an error but a success with an empty result?

Yep, seems to be

errback(new Error(`CachedPackageNotFound for: ${packageName}`));
return;
}
// If there's only 1 chunk, there's nothing to concatenate it with so we can just return it now
if (chunkCount == 1) {
callback(event.target.result);
Expand Down
Loading