LearnNewsExamplesServices
Frontmatter
id8498
titleServiceWorker.preloadAssets crashes on 404s instead of handling errors gracefully
stateClosed
labels
bugaicore
assigneestobiu
createdAtJan 10, 2026, 12:45 PM
updatedAtJan 10, 2026, 12:58 PM
githubUrlhttps://github.com/neomjs/neo/issues/8498
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 10, 2026, 12:58 PM

ServiceWorker.preloadAssets crashes on 404s instead of handling errors gracefully

Closed v11.20.0 bugaicore
tobiu
tobiu commented on Jan 10, 2026, 12:45 PM

The Neo.ServiceWorker.preloadAssets method fails completely if any of the requested URLs return a 404 or network error.

Current Behavior: The method uses cache.addAll(items). If any request in the list fails, cache.addAll rejects the entire promise, adding none of the files to the cache. This results in an unhandled promise rejection or a crash in the calling code.

Error:

RemoteMethodAccess.mjs:216 TypeError: Failed to execute 'addAll' on 'Cache': Request failed

Goal: Make preloadAssets more robust. It should gracefully handle failures, ideally by:

  1. Attempting to add files.
  2. If addAll fails (or by design), iterating and adding files individually so that valid files are cached even if one is missing.
  3. Returning a meaningful response to the caller (e.g., {success: true, failed: ['url1', 'url2']}) instead of crashing.

Proposed Solution: Modify src/worker/ServiceBase.mjs -> preloadAssets to catch errors during fetch/cache operations and report partial successes or specific failures.

tobiu added the bug label on Jan 10, 2026, 12:45 PM
tobiu added the ai label on Jan 10, 2026, 12:45 PM
tobiu added the core label on Jan 10, 2026, 12:45 PM
tobiu assigned to @tobiu on Jan 10, 2026, 12:46 PM
tobiu referenced in commit 9508c44 - "fix: Gracefully handle 404s in ServiceWorker.preloadAssets with success ratio (#8498)" on Jan 10, 2026, 12:58 PM
tobiu
tobiu Jan 10, 2026, 12:58 PM

Input from tobiu:

◆ Refactored preloadAssets to gracefully handle fetch errors (e.g., 404s) and provide detailed result metrics.

New Behavior:

  • No Crash: The method no longer throws/rejects if individual assets fail to load. It catches errors per file.
  • Strict Success: The success flag now indicates strict completion. true only if all requested files are available (pre-cached or successfully fetched). false if any file failed.
  • Success Ratio: Added a ratio property (0 to 1) indicating the percentage of available assets.
  • Detailed Reporting: Returns a failed array containing the URLs that could not be loaded.

Return Object:

{
    failed: ['https://example.com/missing.jpg'],
    ratio: 0.9, // 9/10 successful
    success: false
}

This allows developers to decide whether a partial success is acceptable for their use case.

tobiu closed this issue on Jan 10, 2026, 12:58 PM