Skip to content

Handle error on reader.read error#24450

Closed
joshualim92 wants to merge 1 commit into
mrdoob:devfrom
joshualim92:rethrow-reader-error
Closed

Handle error on reader.read error#24450
joshualim92 wants to merge 1 commit into
mrdoob:devfrom
joshualim92:rethrow-reader-error

Conversation

@joshualim92
Copy link
Copy Markdown

Description

Ran into an edge case where if the network is interrupted during a download, an uncaught network error occurs. Unfortunately FileLoader isn't able to recover from here because the url is still listed in the module level loading object. There is already a catch handler for the fetch call which should handle this case so this is just added in so the error handling is propagated up.

This contribution is funded by VRIFY

@joshualim92 joshualim92 force-pushed the rethrow-reader-error branch from 1ab90e9 to 88c059a Compare August 4, 2022 23:50
Comment thread src/loaders/FileLoader.js Outdated
} ).catch( err => {

}
throw err;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you expecting this to do? Throwing the same error you caught is effectively a no op.

Copy link
Copy Markdown
Author

@joshualim92 joshualim92 Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, when I was running this locally I thought this was sufficient but it was only because something went wrong with my hot reload.

I've replaced the commit I've had before so hopefully it'll be clearer in what the intent is. I'm open to altering the approach though. I'm not sure if a shared error handler is preferred here. Another solution is to switch this to be an async/await so it's easier to have an outer error handle for the recursive promises.

@joshualim92 joshualim92 force-pushed the rethrow-reader-error branch from 88c059a to 9df7cd4 Compare August 5, 2022 06:19
@joshualim92 joshualim92 changed the title Catch and rethrow reader error Handle error on reader.read error Aug 5, 2022
@joshualim92 joshualim92 requested a review from gkjohnson August 5, 2022 15:48
Comment thread src/loaders/FileLoader.js
Comment on lines 123 to 138

function readData() {
if ( done ) {

reader.read().then( ( { done, value } ) => {
controller.close();

if ( done ) {
} else {

controller.close();
loaded += value.byteLength;

} else {
const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
for ( let i = 0, il = callbacks.length; i < il; i ++ ) {

loaded += value.byteLength;
const callback = callbacks[ i ];
if ( callback.onProgress ) callback.onProgress( event );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert these indentation changes? It makes it hard to follow what has meaningfully changed. Please take make a minimal change we can more easily follow the code adjustments.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@joshualim92 joshualim92 requested a review from gkjohnson August 8, 2022 16:19
@joshualim92 joshualim92 force-pushed the rethrow-reader-error branch from 9df7cd4 to 02e5031 Compare August 8, 2022 16:19
@gkjohnson
Copy link
Copy Markdown
Collaborator

Great thanks - can you provide steps on how to reproduce the issue for testing?

@joshualim92
Copy link
Copy Markdown
Author

Great thanks - can you provide steps on how to reproduce the issue for testing?

For sure, the steps involve using the dev tools to get since it's an edge case error while downloading. For ease of testing I created a code sandbox, please let me know if you'd prefer a different format

https://codesandbox.io/s/tender-sinoussi-cjnzko

For ease of testing it uses one of our models that's a little larger.

Steps:

  1. Go to chrome dev tools and throttle the download speed (for ease of turning offline)
  2. Once the .glb file starts downloading, switch the throttle to "Offline"

Expected:
onError callback should be called in loader.load

Actual:
Error isn't called back and instead is uncaught in promise

Screen Shot 2022-08-08 at 2 47 36 PM

@Mugen87
Copy link
Copy Markdown
Collaborator

Mugen87 commented Jun 26, 2024

Should be fixed via #28216.

@Mugen87 Mugen87 closed this Jun 26, 2024
@Mugen87 Mugen87 added this to the r166 milestone Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants