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

Handle errors while loading vector costumes or sounds #3637

Merged
merged 15 commits into from
May 19, 2022

Conversation

kchadha
Copy link
Contributor

@kchadha kchadha commented May 13, 2022

Resolves

Proposed Changes

While loading a vector costume, handle any errors in the process by displaying a gray question mark (same existing behavior) but with this PR, we now we keep track of the original costume data that failed to load.

When serializing the project out, we save the original (potentially broken) costume data instead of the default costume. This prevents data loss from the gray question mark costume overwriting potentially recoverable data (e.g. if the asset server was down when we first tried to load the costume).

Do not save any info about the costume being broken so that we make sure to try and load the costume again if we reload the project.

While the original costume contents are preserved, costume metadata may be fixed in the process of attempting to load the costume (e.g. if the data in the project.json like the costume md5 does not match the actual costume contents).

Update after review cycle and release of storage v2.0.0 & v2.0.1

  • Storage was previously returning an HTML 404 page instead of null when the requested asset was missing
  • Storage was also swallowing errors that it's not forwarding up the chain

This PR pulls in the fixes for these above issues via storage v2.0.1 and addresses handling storage now possibly returning null. This resulted in adding error handling while loading sounds as well. The same behavior described above about using the default sound but serializing what we know about the original sound is used here.

Reason for Changes

This fixes a critical issue that can lead to user data loss.

Test Coverage

  • Added integration tests for .sb3 projects and .sprite3 files with missing or corrupted vector costumes.
  • Added integration tests for .sb3 projects with missing or corrupted sounds

… broken costume data before finishing loading the costume.
…l error handling in one place. Could be used in the future to handle bitmap loading issues as well
Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

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

Looking good -- I especially like the extensive tests!
I marked several items for discussion but it's all little stuff.

src/serialization/sb3.js Outdated Show resolved Hide resolved
src/serialization/serialize-assets.js Outdated Show resolved Hide resolved
src/serialization/serialize-assets.js Outdated Show resolved Hide resolved
src/virtual-machine.js Show resolved Hide resolved
src/virtual-machine.js Outdated Show resolved Hide resolved
test/integration/sb3_corrupted_svg.js Show resolved Hide resolved
test/integration/sb3_corrupted_svg.js Show resolved Hide resolved
test/integration/sb3_missing_svg.js Outdated Show resolved Hide resolved
test/integration/sb3_missing_svg.js Show resolved Hide resolved
test/integration/sprite3_missing_svg.js Show resolved Hide resolved
…04 page was being returned for missing asset data. Update VM to handle null assets properly.
…ge. Track additional metadata for broken costumes: 'bitmapResolution' and 'dataFormat'.
@kchadha kchadha changed the title Don't save default (gray question mark) costume to project.json Handle errors while loading vector costumes or missing sounds May 19, 2022
src/import/load-costume.js Show resolved Hide resolved
@@ -61,6 +95,12 @@ const loadSound = function (sound, runtime, soundBank) {
runtime.storage.load(runtime.storage.AssetType.Sound, md5, ext)
).then(soundAsset => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a catch that ends up at handleSoundLoadError?

Copy link
Contributor

@cwillisf cwillisf May 19, 2022

Choose a reason for hiding this comment

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

Actually, thinking about this further: we should probably have tests that verify loadCostume and loadSound return default assets (with original data in .broken) if storage.load rejects. That might be out of scope for the GQM project, though, as long as what happens now is anything other than a data-loss-by-default-asset situation. (In this case I think it might be an unhandled exception => BSOD?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to leave the error case out so as not to complicate this PR (which was supposed to be focused on vector costumes) too much more. This is similar to how I left off adding a .catch to loadBitmap_ for a later PR as well.

I think there should be a separate PR for broken bitmap costumes and a separate PR for corrupted sounds (or general sound error handling). I just wanted to make sure that we are handling storage.load resolving null in the same PR where we're bringing in the update to storage 2.0.1.

I am hoping to get those other 2 PRs in soon (barring complications I run into testing bitmaps..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nvm! I will address corrupted sound stuff in this PR, since an error thrown here could result in the editor crashing, which might be more likely now that storage is swallowing less errors.

Also I assume you're talking about having unit tests for loadCostume and loadSound in addition to the integration tests? I might add those after this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 8ab21dd to address the sound error handling stuff

obj.name = costume.name;
obj.bitmapResolution = costume.bitmapResolution;

const costumeToSerialize = costume.broken || costume;
Copy link
Contributor

Choose a reason for hiding this comment

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

😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I had been itching to do this for a while but it didn't seem worth it for just 1 or 2 properties but now it's basically all of them! =D

src/virtual-machine.js Outdated Show resolved Hide resolved
kchadha and others added 2 commits May 19, 2022 12:55
Co-authored-by: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com>
Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your persistence!

@cwillisf cwillisf assigned kchadha and unassigned cwillisf May 19, 2022
@kchadha kchadha changed the title Handle errors while loading vector costumes or missing sounds Handle errors while loading vector costumes or sounds May 19, 2022
@kchadha
Copy link
Contributor Author

kchadha commented May 19, 2022

🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 Wohooo!!! 🥳

Thanks for all your help with this work @cwillisf!!! The ambient (and real) pairing was a lot of fun and very much appreciated! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Try to prevent you from messing up your project by saving over your assets with question mark assets
3 participants