#16913·openlayers

loadFeaturesXhr (default loader for many sources) swallows featuresloadend callback errors, making it hard to notice issues

Author: laundmoCreated Jun 16, 2025Updated Sep 28, 2026
Labelsbug

Describe the bug

This bare catch also catches errors raised by feturesloadend callbacks, sending a uninformative featuresloaderror event which does not contain information that the callback failed.

To Reproduce Steps to reproduce the behavior:

  1. register these 2 featuresloadend handlers:
    javascript
    const source = mylayer.getSource();
    source.on("featuresloadstart", () => { console.log("started loading features"); });
    source.on("featuresloadend", () => { throw Error("some error"); });
    source.on("featuresloadend", () => { console.log("features loaded successfully"); });
    source.on("featuresloaderror", (e) => { console.error(e); });
  2. load some features
  3. notice the second featuresloadend handle never runs. It would have been silent, had i not added the featuresloaderror handler, and even like this, i have no clue why it failed.
    > started loading features
    > Object { type: "featuresloaderror", target: Object { ol_uid: "90", ...}, feature: undefined, features: undefined }

Expected behavior I expected errors in featuresloadend handlers to not be swallowed silently by default. I expected to notice a normal error log with traceback in the console if my featuresloadend handler throws an error, which has been the behaviour for any other event handler so far.

I believe this bare except is whats causing this issue, as the second failure here is the callback causing the featuresloaderror event according to my debugger: https://github.com/openlayers/openlayers/blob/b15efa71180d1efee1bd19d15d4d01982fce3b91/src/ol/featureloader.js#L88-L114

My idea for solving this would be by calling the success callback outside this try/catch. Alternatively this could be solved by logging out the error message by default.