[go: up one dir, main page]

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

Fixes unhandled rejection in Skybox.update #12306 #12307

Merged
merged 7 commits into from
Nov 14, 2024
Merged

Fixes unhandled rejection in Skybox.update #12306 #12307

merged 7 commits into from
Nov 14, 2024

Conversation

angrycat9000
Copy link
Contributor
@angrycat9000 angrycat9000 commented Nov 13, 2024

Description

Adds an error handler to loadCubeMap in Skybox.update and then throw any errors during the next call.

This allows the error to be thrown in normal usage when update is called repeatedly. It prevents throwing the error after the end of a test because update is not called after the test ends. Previously the error would be thrown in afterAll when the tests were running.

Issue number and link

Fixes #12306

Testing plan

  1. Checkout this branch
  2. Focus the "handles error when Resources fail to load" spec
  3. Run npm run tests.
    • Verify the tests pass
  4. Run git checkout main -- packages/engine/Source/Scene/SkyBox.js to get the previous version
  5. Run npm run tests.
    • Verify the tests fails with an error in afterAll

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

Thank you for the pull request, @angrycat9000!

✅ We can confirm we have a CLA on file for you.

Copy link
Contributor
@ggetz ggetz left a comment

Choose a reason for hiding this comment

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

Thanks for getting to the bottom of this @angrycat9000! A few comments about how we might fix it.

that._cubeMap = that._cubeMap && that._cubeMap.destroy();
that._cubeMap = cubeMap;
},
function (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason to use the onRejected callback here? Otherwise we typically use catch. Even better would be to use async/await if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, just habit. I can change to catch

I don't want to use await here because that would make the entire Skybox.update function asynchronous instead of just the loading code.

that._cubeMap = cubeMap;
},
function (error) {
console.error("Skybox cube map failed to load", error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Typically, we don't like to log to the console, and prefer throwing errors where possible so the user can deal with it as appropriate for their app. Though the fact that this is in the update loop complicates things.

  1. Ideally, the async code would be removed from the update loop entirely, and there would be a top-level async function like SkyBox.fromCubeMap() or SkyBox.fromImages(). But that may require more refactoring than you're willing to do at this time.
  2. Next best would be to await the promise, catch the error, and throw it synchronously in the next call to update. That way the unit tests can use pollToPromise call update until an error is thrown or _cubeMap is defined.
  3. Finally, as a comprise, could we instead use a oneTimeWarning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 is good. That preserves the expectation that the error is getting thrown, but allows the test to avoid throwing the error (as update is never called second time)

CHANGES.md Outdated Show resolved Hide resolved
- Throw during next call to update
- use catch instead of onRejected
- Don't update CHANGES.md for minor bug
@angrycat9000
Copy link
Contributor Author

Thanks for the feedback @ggetz . Updated and ready for another look

@angrycat9000
Copy link
Contributor Author

Test failure only occurs in release mode. For some reason scene.mode = SceneMode.SCENE2D when the test was run instead of SCENE3D. Gave each test its own instance of Scene to prevent cross test contamination.

@ggetz
Copy link
Contributor
ggetz commented Nov 14, 2024

For some reason scene.mode = SceneMode.SCENE2D when the test was run instead of SCENE3D

The calls with the toThrowDeveloperError expectations are not run in the release tests, so it's likely a side effect of that. The fix here works. 👍

Thanks @angrycat9000, this all looks good!

@ggetz ggetz merged commit 00eb47d into main Nov 14, 2024
9 checks passed
@ggetz ggetz deleted the skybox-error branch November 14, 2024 18:30
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.

CesiumWidgetSpec leaves requests pending after tests finish
2 participants