GeoTIFF / georaster

Wrapper around Georeferenced Rasters like GeoTIFF and soon JPG and PNG that provides a standard interface
Apache License 2.0
81 stars 32 forks source link

parseGeoraster: catching error #71

Closed lsntdev closed 1 year ago

lsntdev commented 1 year ago

Hey guys, I'd like to know how to catch error when parsing the raster. Let assume I have the following code:

reader.readAsArrayBuffer(file);
 reader.onloadend = function() {
    var arrayBuffer = reader.result;
    parseGeoraster(arrayBuffer).then(georaster => {
        console.log(georaster);
    })
     .catch(e => {console.log("got ya")})
};

I expect the "got ya" message (for ex) if the file doesnt have coordinates system but I could not catch the error. Any help will be very welcome :)

DanielJDufour commented 1 year ago

Hi, @lsntdev . This is indeed a problem. Unfortunately, I spent several hours trying to fix this a few months ago and wasn't able to. However, it will be fixed in the next major release of georaster. (I'm not sure when that will be, but I'm hopeful within 6 months).

In the meantime, I invite you to consult the fix that we used for this problem in stac-layer. We basically wrapped the call with a timeout. If the promise didn't complete in a certain amount of time, we rejected it. You can view that code here: https://github.com/stac-utils/stac-layer/blob/main/src/utils/create-georaster-layer.js

Let me know if you have any other questions. I'm sorry for the inconvenience this is causing.

jcphill commented 1 year ago

I'm wondering if this is related to #38, the fix for which didn't address the web worker path. I'm seeing the same uncaught "TypeError: Invalid byte order value." error from fromSource inside onmessage so I'm hoping it can be fixed by simply adding ".catch(postMessage);" or similar in worker.js plus some plumbing on the receiving side, or just by defining a worker.onerror function.