Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRiveFile does not handle errors thrown in RiveFile constructor #267

Open
petersli opened this issue Jun 18, 2024 · 0 comments
Open

useRiveFile does not handle errors thrown in RiveFile constructor #267

petersli opened this issue Jun 18, 2024 · 0 comments

Comments

@petersli
Copy link

petersli commented Jun 18, 2024

I want to use the status returned by the useRiveFile hook to fail gracefully if there is an error while loading the file, e.g. if the file at src is missing.

Currently, if there is an error during the initData method of RiveFile, firing the loadError event is immediately followed by throwing an Error (https://github.com/rive-app/rive-wasm/blob/55691eb4893e3056f2d5096fbc3f2e58142e8d79/js/src/rive.ts#L1453-L1457).

This makes the status returned by useRiveFile provide little value for this use case, since if status === 'failed', the app is going to crash anyways.

This is not an issue when using useRive without useRiveFile, because the call to new RiveFile is wrapped in a try / catch in the Rive constructor (https://github.com/rive-app/rive-wasm/blob/55691eb4893e3056f2d5096fbc3f2e58142e8d79/js/src/rive.ts#L1817-L1824).

I think similarly, useRiveFile should also catch errors thrown by new RiveFile. Without this error handling, I don't think I can use useRiveFile in production.

Other work-arounds also welcome!

Thank you!

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

No branches or pull requests

1 participant