-
Notifications
You must be signed in to change notification settings - Fork 22
better error handling and fix remoteAttachment tests #468
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
|
Claude finished @mchenani's task —— View job PR Review: Better error handling for remote attachmentsI've completed my review of this PR that addresses issue #467. Here's my comprehensive feedback: Todo List:
SummaryThis PR improves error handling for remote attachments and reorganizes tests from unit tests to instrumented tests. The changes make 🚨 Issues to Address1. Redundant Variable Assignments in RemoteAttachmentTest.ktLines 76-77: These assignments appear redundant since the remoteAttachment.contentLength = attachment.data.size()
remoteAttachment.filename = attachment.filenameThe
2. API Breaking ChangeThe
✅ Positive Changes1. Improved Error Handling with Exception ChainingDm.kt:129 and Group.kt:170: Excellent improvement to preserve the original exception as the cause: throw XMTPException("Failed to encode content: ${e.message}", e)This maintains the full stack trace, making debugging significantly easier. This is a Kotlin/Android best practice. 2. Flexible Optional Field HandlingRemoteAttachmentCodec.kt:165-171: Making content.contentLength?.let {
parametersMap["contentLength"] = it.toString()
}
content.filename?.let {
parametersMap["filename"] = it
}The codec gracefully handles missing fields during both encoding (lines 165-171) and decoding (lines 186-187). This follows Kotlin's idiomatic null safety patterns. 3. Test Infrastructure ImprovementsTestHelpers.kt:117-121: The new class TestFetcher(val filesDir: File) : Fetcher {
override fun fetch(url: URL): ByteArray {
return File(filesDir, url.toString().replace("https://", "")).readBytes()
}
}This is well-designed for testing purposes. Moving 4. Proper Test Setup with @beforeRemoteAttachmentTest.kt:26-31: Good use of 🔍 Code Quality & Kotlin/Android Best Practices✅ Excellent Practices Observed
|
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.
Pull Request Overview
This PR improves error handling across the XMTP Android library and fixes issues in the remote attachment tests. The primary focus is on providing more descriptive error messages and ensuring the remote attachment functionality works properly with the updated API.
- Better error handling with more informative exception messages that include the underlying cause
- Fixed remote attachment codec to properly handle filename and contentLength parameters with null checks
- Updated remote attachment tests to work with current test infrastructure and removed flaky test annotations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| RemoteAttachmentCodec.kt | Enhanced parameter validation and error handling for remote attachment encoding |
| Group.kt | Improved error message to include underlying exception details |
| Dm.kt | Improved error message to include underlying exception details |
| TestHelpers.kt | Added TestFetcher class for testing remote attachment functionality |
| RemoteAttachmentTest.kt | Fixed test setup, updated method calls, and removed flaky test annotations |
| GroupTest.kt | Added comprehensive test for group membership and activity state after removal and restart |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| import com.google.protobuf.ByteString | ||
| import com.google.protobuf.kotlin.toByteString | ||
| import com.google.protobuf.kotlin.toByteStringUtf8 | ||
| import org.checkerframework.checker.units.qual.Length |
Copilot
AI
Sep 3, 2025
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.
This import appears to be unused and unrelated to the functionality. The @Length annotation from checker framework is for unit checking of length measurements, which doesn't seem relevant to this remote attachment codec.
| import org.checkerframework.checker.units.qual.Length |
| content.contentLength?.let { contentLength -> | ||
| parametersMap["contentLength"] = contentLength.toString() | ||
| } ?: throw XMTPException("missing contentLength") | ||
|
|
||
| content.filename?.let { fileName -> | ||
| parametersMap["filename"] = fileName | ||
| } ?: throw XMTPException("missing filename") | ||
|
|
||
|
|
Copilot
AI
Sep 3, 2025
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.
[nitpick] There's an extra blank line at line 173 that should be removed to maintain consistent spacing.
| content.contentLength?.let { contentLength -> | |
| parametersMap["contentLength"] = contentLength.toString() | |
| } ?: throw XMTPException("missing contentLength") | |
| content.filename?.let { fileName -> | |
| parametersMap["filename"] = fileName | |
| } ?: throw XMTPException("missing filename") |
| remoteAttachment.contentLength = attachment.data.size() | ||
| remoteAttachment.filename = attachment.filename | ||
|
|
||
| val fixtures = fixtures() | ||
| val aliceClient = fixtures.aliceClient | ||
|
|
Copilot
AI
Sep 3, 2025
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.
These assignments are redundant since the RemoteAttachment.from() method now takes filename and contentLength as parameters and sets them during construction. These lines should be removed.
|
|
||
| // Verify that after restart, the group is found and isActive still returns false | ||
| assertNotNull(caroGroupAfterRestart) | ||
| // runBlocking { caroGroupAfterRestart!!.sync() } |
Copilot
AI
Sep 3, 2025
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.
Commented-out code should be removed rather than left in the codebase. If sync is not needed, remove this line entirely.
| // runBlocking { caroGroupAfterRestart!!.sync() } |
Preserve exception causes in
|
|
Claude finished @mchenani's task —— View job PR Review: Better error handling for remote attachmentsI've completed my review of this PR that addresses issue #467. Here's my comprehensive feedback: Todo List:
SummaryThis PR makes error handling and test organization improvements, but there are several issues that should be addressed before merging: 🚨 Critical Issues1. Unused Import in RemoteAttachmentCodec.ktLine 6: The import 2. Redundant Variable Assignments in RemoteAttachmentTest.ktLines 76-78: These assignments are redundant since remoteAttachment.contentLength = attachment.data.size() // Redundant
remoteAttachment.filename = attachment.filename // RedundantThese fields should either be set in the 3. Commented-Out Code in GroupTest.ktLine 504: There's commented-out code that should be removed or uncommented if needed: // runBlocking { caroGroupAfterRestart!!.sync() }
|
|
Claude finished @mchenani's task —— View job PR Review: Better error handling for remote attachmentsI've completed my review of this PR that addresses issue #467. Here's my comprehensive feedback: Todo List:
SummaryThis PR improves error handling for remote attachments and test infrastructure. The changes are generally good, making 🚨 Issues to Address1. Redundant Variable Assignments in RemoteAttachmentTest.ktLines 76-77: These assignments appear redundant since remoteAttachment.contentLength = attachment.data.size() // Line 76
remoteAttachment.filename = attachment.filename // Line 77These assignments are setting fields that should already be handled in the creation process. Consider removing these lines if they're not needed. 2. API Breaking ChangeThe change to
This could break existing client code. Consider documenting this as a breaking change in the release notes. ✅ Positive Changes1. Better Error MessagesThe improved error handling in throw XMTPException("Failed to encode content: ${e.message}", e)This makes debugging much easier by maintaining the full stack trace. 2. Flexible Parameter HandlingMaking content.contentLength?.let {
parametersMap["contentLength"] = it.toString()
}
content.filename?.let {
parametersMap["filename"] = it
}The codec gracefully handles missing fields during decoding as well. 3. Test Infrastructure Improvements
class TestFetcher(val filesDir: File) : Fetcher {
override fun fetch(url: URL): ByteArray {
return File(filesDir, url.toString().replace("https://", "")).readBytes()
}
}🔍 Code Quality & Kotlin/Android Best Practices✅ Good Practices
|
|
Claude finished @mchenani's task —— View job PR Review: Better error handling for remote attachmentsI've completed my review of this PR that addresses issue #467. Here's my comprehensive feedback: Todo List:
SummaryThis PR improves error handling for remote attachments and reorganizes tests. The changes are generally good, making 🚨 Critical Issues1. Redundant Variable Assignments in RemoteAttachmentTest.ktLines 76-77: These assignments appear redundant since remoteAttachment.contentLength = attachment.data.size() // Line 76
remoteAttachment.filename = attachment.filename // Line 77These should be removed if they're not needed, or the 2. API Breaking ChangeThe change to
This could break existing client code. Consider documenting this as a breaking change in the release notes. ✅ Positive Changes1. Better Error MessagesThe improved error handling in throw XMTPException("Failed to encode content: ${e.message}", e)This makes debugging much easier by maintaining the full stack trace. 2. Flexible Parameter HandlingMaking content.contentLength?.let {
parametersMap["contentLength"] = it.toString()
}
content.filename?.let {
parametersMap["filename"] = it
}The codec gracefully handles missing fields during decoding as well. 3. Test Infrastructure Improvements
class TestFetcher(val filesDir: File) : Fetcher {
override fun fetch(url: URL): ByteArray {
return File(filesDir, url.toString().replace("https://", "")).readBytes()
}
}4. Coroutine Best PracticesThe addition of 🔍 Code Quality & Kotlin/Android Best Practices✅ Good Practices
|
closes #467