-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[file_packager.py] Fix errback call in fetchRemotePackage
#24871
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
Changes from 10 commits
a423463
36a127e
72abcbd
9018a3c
e0c6311
fb0be1e
19d1d53
19df551
633b44e
f566133
87e45dc
9e11b66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -635,7 +635,12 @@ def generate_js(data_target, data_files, metadata): | |
|
|
||
| if options.support_node: | ||
| ret += " var isNode = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';\n" | ||
| ret += ' function loadPackage(metadata) {\n' | ||
| ret += ''' | ||
| function throwPackageError(error) { | ||
| throw error; | ||
| }; | ||
|
|
||
| function loadPackage(metadata) {\n''' | ||
|
|
||
| code = ''' | ||
| function assert(check, msg) { | ||
|
|
@@ -972,10 +977,10 @@ def generate_js(data_target, data_files, metadata): | |
| %(node_support_code)s | ||
| Module['dataFileDownloads'] ??= {}; | ||
| fetch(packageName) | ||
| .catch((cause) => Promise.reject(new Error(`Network Error: ${packageName}`, {cause}))) // If fetch fails, rewrite the error to include the failing URL & the cause. | ||
| .catch((cause) => errback(new Error(`Network Error: ${packageName}`, {cause}))) // If fetch fails, rewrite the error to include the failing URL & the cause. | ||
| .then((response) => { | ||
| if (!response.ok) { | ||
| return Promise.reject(new Error(`${response.status}: ${response.url}`)); | ||
| return errback(new Error(`${response.status}: ${response.url}`)); | ||
| } | ||
|
|
||
| if (!response.body && response.arrayBuffer) { // If we're using the polyfill, readers won't be available... | ||
|
|
@@ -984,7 +989,7 @@ def generate_js(data_target, data_files, metadata): | |
|
|
||
| const reader = response.body.getReader(); | ||
| const iterate = () => reader.read().then(handleChunk).catch((cause) => { | ||
| return Promise.reject(new Error(`Unexpected error while handling : ${response.url} ${cause}`, {cause})); | ||
| return errback(new Error(`Unexpected error while handling : ${response.url} ${cause}`, {cause})); | ||
| }); | ||
|
|
||
| const chunks = []; | ||
|
|
@@ -1022,10 +1027,6 @@ def generate_js(data_target, data_files, metadata): | |
| Module['setStatus']?.('Downloading data...'); | ||
| return iterate(); | ||
| }); | ||
| }; | ||
|
|
||
| function handleError(error) { | ||
| console.error('package error:', error); | ||
| };\n''' % {'node_support_code': node_support_code} | ||
|
|
||
| code += ''' | ||
|
|
@@ -1048,7 +1049,7 @@ def generate_js(data_target, data_files, metadata): | |
| function preloadFallback(error) { | ||
| console.error(error); | ||
| console.error('falling back to default preload behavior'); | ||
| fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, handleError); | ||
| fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, throwPackageError); | ||
| }; | ||
|
|
||
| openDatabase( | ||
|
|
@@ -1088,7 +1089,7 @@ def generate_js(data_target, data_files, metadata): | |
| } else { | ||
| fetched = data; | ||
| } | ||
| }, handleError);\n''' | ||
| }, throwPackageError);\n''' | ||
|
|
||
| code += ''' | ||
| Module['preloadResults'][PACKAGE_NAME] = {fromCache: false}; | ||
|
|
@@ -1117,7 +1118,7 @@ def generate_js(data_target, data_files, metadata): | |
| if (isNode) { | ||
| require('fs').readFile(metadataUrl, 'utf8', (err, contents) => { | ||
| if (err) { | ||
| return Promise.reject(err); | ||
| throwPackageError(err); | ||
| } else { | ||
| loadPackage(JSON.parse(contents)); | ||
| } | ||
|
|
@@ -1138,8 +1139,10 @@ def generate_js(data_target, data_files, metadata): | |
| if (response.ok) { | ||
| return response.json(); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you still need to do something here when the response is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actaully I think just doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder now, if we take this code: function preloadFallback(error) {
console.error(error);
console.error('falling back to default preload behavior');
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, throwPackageError);
};
openDatabase(
(db) => checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
(useCached, metadata) => {
Module['preloadResults'][PACKAGE_NAME] = {fromCache: useCached};
if (useCached) {
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, metadata, processPackageData, preloadFallback);
} else {
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
(packageData) => {
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
(error) => {
console.error(error);
processPackageData(packageData);
});
}
, preloadFallback);
}
}, preloadFallback)
, preloadFallback);then this catch in fetchRemotePackage will not fail Module['dataFileDownloads'] ??= {};
fetch(packageName)
.catch((cause) => errback(new Error(`Network Error: ${packageName}`, {cause}))) // If fetch fails, rewrite the error to include the failing URL & the cause.
.then((response) => {I think that just adding promise Rejsect here for security iss what we want |
||
| return Promise.reject(new Error(`${response.status}: ${response.url}`)); | ||
lkwinta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| .catch((cause) => | ||
| throwPackageError(new Error(`Network Error: ${packageName}`, {cause})) | ||
| ) // If fetch fails, rewrite the error to include the failing URL & the cause. | ||
| .then(loadPackage); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this
returnis needed here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree,