emscripten-core / emscripten-core/emscripten

file_packager.py: option to continue-on-error in output js (for optional packages)?

Open
#21,310 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Currently, when using `file_packager.py` to generate a preload package*, the output .js code will throw an error inside `fetchRemotePackage` if the associated `.data` file cannot be downloaded. This then yields a state where loading the Module is blocked indefinitely.

* (via `file_packager.py --preload [...] --js-output=packageName.js --use-preload-cache`)

In the case of optional packages (which an application can handle running without), we'd like to essentially swallow this error and allow loading / running to continue.

The specific use-case: We have optional packages, and an application we're trying to make resilient in offline scenarios (ex. when the .data files for those packages aren't cached). The application can already handle if the optional packages aren't present, so all that's needed is functionality in the `file_packager` generated script to gracefully handle the error case and remove the run dependencies.

Thoughts on options?

One idea:

Have `file_packager.py` take a new `--continue-on-fetch-error`/`--continue-on-loading-error`/`--continue-on-error` (?) option that adapts the output .js code to:
1. Log any error, but either handle or not throw:
`throw new Error("NetworkError for: " + packageName);`
`throw new Error(xhr.statusText + " : " + xhr.responseURL);`
(which currently end up as unhandled errors)
2. (Optionally) Call a special event on Module that could be implemented for external pre/post-js scripts that want to do custom error handling
3. Remove all run dependencies on error, so that running is unblocked
`Module['removeRunDependency']('datafile_.data');`
``Module['removeRunDependency'](`fp ${that.name}`);`` (for all dependencies added as a result of `DataRequest.open` calls in `runWithFS`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.