-
-
Couldn't load subscription status.
- Fork 370
refactor: Migrate SentryMsgPackSerializer from Objective-C to Swift #6143
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
base: main
Are you sure you want to change the base?
Conversation
…nverted tests - Updated SentryMsgPackSerializer to log errors instead of debug messages for empty data and input stream issues. - Modified the `asInputStream` method in the SentryStreamable protocol to return nullable streams. - Removed outdated Objective-C tests and added comprehensive Swift tests for SentryMsgPackSerializer, covering various scenarios including nil input streams and invalid file paths. - Ensured proper cleanup of temporary files in tests.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6143 +/- ##
========================================
Coverage ? 86.925%
========================================
Files ? 454
Lines ? 37654
Branches ? 17422
========================================
Hits ? 32731
Misses ? 4645
Partials ? 278
Continue to review full report in Codecov by Sentry.
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 5c5648e | 1234.44 ms | 1253.79 ms | 19.35 ms |
| fb48c9a | 1232.49 ms | 1266.27 ms | 33.78 ms |
| d72784d | 1214.31 ms | 1241.35 ms | 27.04 ms |
| 7af87c1 | 1229.31 ms | 1253.84 ms | 24.53 ms |
| 029a804 | 1219.65 ms | 1241.96 ms | 22.30 ms |
| 139db8b | 1231.50 ms | 1258.19 ms | 26.69 ms |
| 7f4bf81 | 1241.73 ms | 1270.66 ms | 28.93 ms |
| 83bb978 | 1238.33 ms | 1260.04 ms | 21.71 ms |
| 42cfd79 | 1222.13 ms | 1244.23 ms | 22.10 ms |
| aac24ac | 1225.94 ms | 1256.38 ms | 30.45 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 5c5648e | 23.75 KiB | 879.60 KiB | 855.86 KiB |
| fb48c9a | 23.75 KiB | 1006.34 KiB | 982.59 KiB |
| d72784d | 23.75 KiB | 988.01 KiB | 964.27 KiB |
| 7af87c1 | 23.75 KiB | 933.34 KiB | 909.59 KiB |
| 029a804 | 23.75 KiB | 928.11 KiB | 904.36 KiB |
| 139db8b | 23.75 KiB | 920.64 KiB | 896.89 KiB |
| 7f4bf81 | 23.75 KiB | 919.70 KiB | 895.95 KiB |
| 83bb978 | 23.75 KiB | 920.64 KiB | 896.89 KiB |
| 42cfd79 | 23.75 KiB | 880.20 KiB | 856.45 KiB |
| aac24ac | 23.75 KiB | 1019.17 KiB | 995.42 KiB |
Previous results on branch: philprime/msg-pack-serializer-null-handling
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 13910c9 | 1222.09 ms | 1248.02 ms | 25.93 ms |
| 2c09b1c | 1196.13 ms | 1225.79 ms | 29.66 ms |
| 43dc3b5 | 1236.69 ms | 1255.65 ms | 18.95 ms |
| 8215a0d | 1206.23 ms | 1237.04 ms | 30.81 ms |
| c0e1523 | 1229.65 ms | 1263.41 ms | 33.76 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 13910c9 | 23.74 KiB | 1.00 MiB | 1002.97 KiB |
| 2c09b1c | 23.75 KiB | 992.26 KiB | 968.52 KiB |
| 43dc3b5 | 23.75 KiB | 988.55 KiB | 964.80 KiB |
| 8215a0d | 23.75 KiB | 969.21 KiB | 945.46 KiB |
| c0e1523 | 23.75 KiB | 988.63 KiB | 964.88 KiB |
…rializer-null-handling
…nal serialization tests - Added support for error streams in TestStreamableObject. - Introduced new test cases for serializing empty dictionaries, single elements, large dictionaries, long keys, and handling invalid paths. - Implemented a custom ErrorInputStream to simulate read errors during serialization.
…ntation - Deleted the Objective-C SentryMsgPackSerializer and its associated header files. - Introduced a new Swift implementation of SentryMsgPackSerializer with improved error handling. - Added SentryStreamable protocol and extensions for Data, NSData, NSURL, and URL to support serialization. - Updated tests to validate the new Swift serialization logic and error handling.
…r error propagation - Changed keyData.withUnsafeBytes to use try for improved error handling. - This ensures that any errors during buffer address retrieval are properly thrown.
|
@cursor review |
- Introduced TestStreamableObject to simulate various SentryStreamable behaviors, including handling nil and error streams. - Updated SentryMsgPackSerializerTests to utilize TestStreamableObject for improved test coverage on serialization scenarios. - Removed redundant TestStreamableObject implementation from SentryMsgPackSerializerTests to streamline code.
…rializer-null-handling
…rializer-null-handling
|
@sentry review |
…rializer-null-handling
…ror handling - Updated `serializeDictionary` method to directly serialize to a file. - Introduced `serializeToFile` method for better separation of concerns. - Enhanced error handling to clean up partial files on serialization failure. - Updated tests to validate new serialization approach and error scenarios.
| * We only need to concatenate a list of NSData into an envelope item. | ||
| */ | ||
| class SentryMsgPackSerializer { | ||
| @objc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the class itself is not marked with @objc I guess this is only called from Swift? Can we remove this objc?
| * This is a partial implementation of the MessagePack format. | ||
| * We only need to concatenate a list of NSData into an envelope item. | ||
| */ | ||
| class SentryMsgPackSerializer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final?
| */ | ||
| class SentryMsgPackSerializer { | ||
| @objc | ||
| static func serializeDictionary(toMessagePack dictionary: [String: Any], intoFile fileURL: URL) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this input type [String: SentryStreamable] I think we can since the function doesn't need to be exposed to objc.
| } | ||
|
|
||
| // swiftlint:disable:next function_body_length cyclomatic_complexity | ||
| private static func serializeToFile(dictionary: [String: Any], fileURL: URL) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we change the above not to use Any, can change this as well
| guard let value = anyValue as? SentryStreamable else { | ||
| throw SentryMsgPackSerializerError.invalidValue("Value does not conform to SentryStreamable: \(anyValue)") | ||
| } | ||
| guard let keyData = key.data(using: .utf8) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use Data(key.utf8) and then it won't be optional
|
|
||
| // Write UInt32 as big endian bytes | ||
| let lengthBytes = [ | ||
| UInt8((valueLength >> 24) & 0xFF), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we still use NSSwapHostIntToBig like the objc code did? That function should be available to Swift
Summary
This PR migrates the SentryMsgPackSerializer from Objective-C to Swift while maintaining 100% behavioral compatibility.
Changes Made
Complete Migration
SentryMsgPackSerializer.m/.hto modular Swift implementationSources/Swift/Tools/MsgPack/directory:SentryMsgPackSerializer.swift- Main serialization logicSentryStreamable.swift- Protocol definitionSentryMsgPackSerializerError.swift- Error typesData+SentryStreamable.swift- Data extensionURL+SentryStreamable.swift- URL extensionNSData+SentryStreamable.swift- NSData extensionNSURL+SentryStreamable.swift- NSURL extensionBehavioral Compatibility
Enhanced Test Coverage
Implementation Improvements
SentryMsgPackSerializerErrorKey Technical Details
streamSize() -> Intto support -1 error values from Objective-CUInt8(truncatingIfNeeded:)to match Objective-C silent truncationData.write(to:)methodTesting
All existing functionality verified through comprehensive test suite:
Closes #6140
#skip-changelog