Skip to content

Implement loadStructuredBinaryData from updated AssetBundle#1272

Merged
marandaneto merged 4 commits into
mainfrom
unknown repository
Feb 28, 2023
Merged

Implement loadStructuredBinaryData from updated AssetBundle#1272
marandaneto merged 4 commits into
mainfrom
unknown repository

Conversation

@arnemolland

Copy link
Copy Markdown
Contributor

📜 Description

Implements loadStructuredBinaryData, which is a new method added to Flutter's abstract AssetBundle class in flutter/flutter#119277.

💡 Motivation and Context

This change has to be included in order to support what is now the master channel of Flutter and what will hit stable down the road.

💚 How did you test it?

Duped and tweaked the tests for loadStructuredData.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

Comment thread flutter/test/sentry_asset_bundle_test.dart Outdated
@marandaneto

Copy link
Copy Markdown
Contributor

Thank you @arnemolland
We'll have to wait for this to land at least on the beta channel, otherwise, it'd be breaking for people using the stable/beta channels.

@ueman

ueman commented Feb 14, 2023

Copy link
Copy Markdown
Collaborator

It can be made backwards compatible as shown in #1166 (comment)

@arnemolland

Copy link
Copy Markdown
Contributor Author

It can be made backwards compatible as shown in #1166 (comment)

Updated the PR, would you prefer not using the inner asset bundle?

@codecov

codecov Bot commented Feb 20, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.06 🎉

Comparison is base (d301b11) 89.76% compared to head (0b1a611) 89.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1272      +/-   ##
==========================================
+ Coverage   89.76%   89.83%   +0.06%     
==========================================
  Files         155      155              
  Lines        5032     5064      +32     
==========================================
+ Hits         4517     4549      +32     
  Misses        515      515              
Impacted Files Coverage Δ
flutter/lib/src/sentry_asset_bundle.dart 94.91% <100.00%> (+1.89%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ueman ueman left a comment

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.

This PR is currently failing because bundle.loadStructuredBinaryData isn't available on the min Flutter version which Sentry supports. Therefore, we need to apply the suggested "hack" to make it compatible with the min as well as the max Flutter versions supported by Sentry.

You also need to add a changelog entry.

This PR fixes:

(They're marked as completed because of this PR, I guess)

Comment thread flutter/lib/src/sentry_asset_bundle.dart
Comment thread flutter/lib/src/sentry_asset_bundle.dart Outdated
@arnemolland

Copy link
Copy Markdown
Contributor Author

Thanks! Added the suggested changes.

@arnemolland

Copy link
Copy Markdown
Contributor Author

Fixed an issue with type argument not being implicitly forwarded to the dynamic (bundle as dynamic).loadStructuredBinaryData call and rebased on top of the latest changes. Let me know if anything is missing.

@arnemolland
arnemolland requested review from ueman and removed request for brustolin and krystofwoldrich February 22, 2023 23:49
Comment thread CHANGELOG.md Outdated
@arnemolland
arnemolland requested a review from ueman February 23, 2023 18:56
@marandaneto

Copy link
Copy Markdown
Contributor

@arnemolland since this is possible using the override_on_non_overriding_member and it's not a breaking change any more.
Can you target the main branch instead? so we can release this with the current stable version.

@arnemolland

arnemolland commented Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

@arnemolland since this is possible using the override_on_non_overriding_member and it's not a breaking change any more.
Can you target the main branch instead? so we can release this with the current stable version.

Sure thing, I'll rebase

@arnemolland
arnemolland changed the base branch from v7.0.0 to main February 27, 2023 10:47
@marandaneto

Copy link
Copy Markdown
Contributor

There are some conflicts, search for <<<<<<< HEAD.
Also, the changelog should be under the Unreleased (v6)

@arnemolland

Copy link
Copy Markdown
Contributor Author

There are some conflicts, search for <<<<<<< HEAD.
Also, the changelog should be under the Unreleased (v6)

Had to tidy up locally, should be good now.

@arnemolland
arnemolland requested review from marandaneto and removed request for ueman February 27, 2023 12:41
Comment thread flutter/lib/src/sentry_asset_bundle.dart
Comment thread CHANGELOG.md Outdated

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @arnemolland

@marandaneto

Copy link
Copy Markdown
Contributor

@arnemolland there are 4 failing tests, mind checking out?

@arnemolland

Copy link
Copy Markdown
Contributor Author

@arnemolland there are 4 failing tests, mind checking out?

Yes, seems to be related to tests running from stable trying to invoke the non-existing method, fixing that asap.

@arnemolland

Copy link
Copy Markdown
Contributor Author

@arnemolland there are 4 failing tests, mind checking out?

Yes, seems to be related to tests running from stable trying to invoke the non-existing method, fixing that asap.

As expected, calling loadStructuredBinaryData on the inner bundle is no good for SDK versions <3.8. That wouldn't happen since it can't be called, but the test runner doesn't care since we're trying to call it directly instead of interfacing with an AssetBundle (as normal usage would be).

The quickest fix is to apply the second suggestion found here -- updating the PR.

@arnemolland
arnemolland requested review from marandaneto and ueman and removed request for ueman February 27, 2023 22:21
@arnemolland

Copy link
Copy Markdown
Contributor Author

My solution to the above problem was to refactor the code to emulate the AssetBundle's loadStructuredBinaryData implementation, so that we don't call the inner bundle and avoid the testing problem;

Future<T> _loadStructuredBinaryDataWrapper<T>(
    String key,
    FutureOr<T> Function(ByteData data) parser,
  ) async {
    final ByteData data = await load(key);
    return parser(data);
  }

This can be refactored back once the library drops backwards compatibility with Flutter < 3.8. LMK if this is an acceptable approach.

@ueman

ueman commented Feb 28, 2023

Copy link
Copy Markdown
Collaborator

I don't think emulating is the way to go, as the loadStructuredBinaryData has quite a sophisticated implementation, which would be bypassed by emulating it. See https://master-api.flutter.dev/flutter/services/CachingAssetBundle/loadStructuredBinaryData.html
One particular drawback would be to basically remove the ability of the CachingAssetBundle to cache data for loadStructuredBinaryData.

Instead, you can adjust the TestAssetBundle and add loadStructuredBinaryData as a method just like in

@override
// This is an override on Flutter greater than 3.1
// ignore: override_on_non_overriding_member
Future<ImmutableBuffer> loadBuffer(String key) async {
if (throwException) {
throw Exception('exception thrown for testing purposes');
}
if (key == _testFileName) {
return ImmutableBuffer.fromUint8List(
Uint8List.fromList(utf8.encode('Hello World!')));
}
return ImmutableBuffer.fromUint8List(Uint8List.fromList([]));
}

Because the newly introduced method is then also available in all Flutter versions in the tests, every thing should be working.

I've done that in the past, see #877 as a reference how to do that.

@arnemolland

Copy link
Copy Markdown
Contributor Author

I don't think emulating is the way to go, as the loadStructuredBinaryData has quite a sophisticated implementation, which would be bypassed by emulating it. See https://master-api.flutter.dev/flutter/services/CachingAssetBundle/loadStructuredBinaryData.html One particular drawback would be to basically remove the ability of the CachingAssetBundle to cache data for loadStructuredBinaryData.

Instead, you can adjust the TestAssetBundle and add loadStructuredBinaryData as a method just like in

@override
// This is an override on Flutter greater than 3.1
// ignore: override_on_non_overriding_member
Future<ImmutableBuffer> loadBuffer(String key) async {
if (throwException) {
throw Exception('exception thrown for testing purposes');
}
if (key == _testFileName) {
return ImmutableBuffer.fromUint8List(
Uint8List.fromList(utf8.encode('Hello World!')));
}
return ImmutableBuffer.fromUint8List(Uint8List.fromList([]));
}

Because the newly introduced method is then also available in all Flutter versions in the tests, every thing should be working.

I've done that in the past, see #877 as a reference how to do that.

Perfect, thanks!

@arnemolland
arnemolland requested review from ueman and removed request for marandaneto February 28, 2023 10:21
@marandaneto
marandaneto merged commit 2d3b03d into getsentry:main Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants