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

Pass errors into Stream Callbacks #1182

Merged
merged 9 commits into from
Oct 25, 2024
Merged

Conversation

insipx
Copy link
Contributor

@insipx insipx commented Oct 23, 2024

closes #899

rel: #1149

Summary by CodeRabbit

  • New Features

    • Introduced new error handling mechanisms with the SubscribeError enum for improved subscription processes.
    • Enhanced logging and error reporting in synchronization and message processing methods.
  • Bug Fixes

    • Streamlined error handling in various methods, ensuring clearer feedback and robustness in message processing.
  • Documentation

    • Updated scripts and commands for generating bindings to reflect new structures and error handling.
  • Chores

    • Modified dependency versions and configurations for better compatibility and performance.

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Warning

Rate limit exceeded

@insipx has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 57a9c0d and f510fcf.

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing error handling and refining function signatures within the XMTP codebase. Key modifications include the addition of new error types, adjustments to the visibility of struct fields, and updates to method signatures to propagate errors effectively. Additionally, configuration settings for Rust Analyzer have been added to improve diagnostics. Changes to dependency management in Cargo.toml files and updates to scripts for generating bindings further reflect an overall enhancement of the project's robustness and maintainability.

Changes

File Change Summary
.vscode/settings.json Added settings to enable diagnostics for Rust Analyzer and specified disabled diagnostics.
bindings_node/src/conversations.rs Updated methods to simplify handling of NapiGroup instances by using into method instead of NapiGroup::new. Adjusted error handling in stream and stream_all_messages methods.
bindings_node/src/groups.rs Introduced From trait implementation for NapiGroup to enable conversion from MlsGroup<RustXmtpClient>. Enhanced error handling in the stream method.
xmtp_mls/src/builder.rs Removed InboxIdMismatch variant from ClientBuilderError enum.
xmtp_mls/src/groups/mod.rs Changed visibility of client field in MlsGroup from pub(crate) to pub. Added new error variants to GroupError enum.
xmtp_mls/src/groups/subscriptions.rs Updated methods to return Result<StoredGroupMessage, SubscribeError> instead of previous error types, enhancing error handling.
xmtp_mls/src/groups/sync.rs Enhanced error handling and logging in synchronization methods.
xmtp_mls/src/lib.rs Modified error logging in the optify! macro to use Display trait instead of Debug.
xmtp_mls/src/subscriptions.rs Introduced SubscribeError enum for subscription-related errors. Updated method signatures to return results with the new error type.
Cargo.toml Updated dependency versions and added new dependencies with specific features. Adjusted profile settings and added a patch section for certain dependencies.
bindings_ffi/Cargo.toml Updated uniffi dependency features and changed binary path for ffi-uniffi-bindgen.
bindings_ffi/Makefile Updated command for generating Swift bindings with Uniffi.
bindings_ffi/gen_kotlin.sh Enhanced script to check for the existence of the xmtp-android directory and updated the build command for generating Kotlin bindings.
bindings_ffi/src/lib.rs Added new error type FfiSubscribeError and a new variant to GenericError.
bindings_ffi/src/mls.rs Refined error handling in create_client and updated FfiConversation struct to encapsulate MlsGroup. Adjusted callback interfaces for message and conversation streaming.
dev/release-kotlin Added a conditional block to manage the jniLibs directory based on user input.

Assessment against linked issues

Objective Addressed Explanation
Pass stream errors through to callbacks (Issue #899)
Update function signatures to return Result<> types for stream methods
Ensure error handling in with_callback variants passes errors correctly

Possibly related PRs

Suggested reviewers

  • nplasterer

Poem

🐰 In the code where bunnies play,
New paths and errors find their way.
With streams that sing and logs that cheer,
We hop along, no need to fear!
So let’s embrace this code so bright,
A joyful dance in the coding light! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@insipx insipx force-pushed the insipx/stream-error-callbacks branch from e688233 to 9fd8190 Compare October 24, 2024 14:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🧹 Outside diff range and nitpick comments (5)
.vscode/settings.json (1)

5-10: LGTM! Consider additional FFI-related diagnostic settings.

The addition of Rust Analyzer diagnostic settings is appropriate and will help with development of the error handling improvements. The disabled diagnostics are reasonable choices given the codebase's use of FFI and macros.

Consider adding these additional settings to improve FFI development experience:

   "rust-analyzer.diagnostics.disabled": [
     "unlinked-file",
     "unresolved-macro-call",
     "unresolved-proc-macro"
-  ],
+  ],
+  "rust-analyzer.check.command": "clippy",
+  "rust-analyzer.check.extraArgs": ["--", "-W", "clippy::all", "-W", "clippy::nursery"],

This will enable Clippy's FFI and safety-related lints during development, which could help catch potential FFI boundary issues early.

xmtp_mls/src/lib.rs (1)

Line range hint 91-95: Maintain consistent error formatting across macro variants.

While the first variant of the macro now uses the Display format ({}), the second variant still uses Debug format ({:?}). This creates inconsistency in error logging.

Apply this diff to maintain consistency:

    ( $e: expr, $msg: tt ) => {
        match $e {
            Ok(v) => Some(v),
            Err(e) => {
-                tracing::error!("{}: {:?}", $msg, e);
+                tracing::error!("{}: {}", $msg, e);
                None
            }
        }
    };
bindings_node/src/conversations.rs (1)

Line range hint 235-245: Consider applying similar error handling to stream_all_messages.

For consistency with the improved error handling in the stream method, consider updating the stream_all_messages callback to handle potential errors:

   move |message| {
-    tsfn.call(Ok(message.into()), ThreadsafeFunctionCallMode::Blocking);
+    tsfn.call(
+      Ok(message)
+        .map(NapiMessage::from)
+        .map_err(ErrorWrapper::from)
+        .map_err(Error::from),
+      ThreadsafeFunctionCallMode::Blocking,
+    );
   },

This would ensure consistent error handling across both streaming methods.

bindings_node/src/groups.rs (1)

561-567: LGTM: Improved error handling in stream callback

The changes successfully implement error propagation through the FFI boundary by properly mapping and converting errors. This aligns with the PR objective to pass stream errors through to callbacks, allowing external SDKs to handle errors appropriately.

Consider documenting the error types that can be passed through the callback in the TypeScript type definition, as this represents a potentially breaking change in error handling behavior.

xmtp_mls/src/groups/subscriptions.rs (1)

106-106: Remove commented-out code for cleanliness

The commented-out line appears unnecessary and can be removed to improve code readability.

Apply this diff to remove the commented code:

-    // .map_err(|e| GroupError::Generic(e.to_string()))?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 13ec55c and 9fd8190.

⛔ Files ignored due to path filters (1)
  • bindings_wasm/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • .vscode/settings.json (1 hunks)
  • bindings_node/src/conversations.rs (1 hunks)
  • bindings_node/src/groups.rs (2 hunks)
  • xmtp_mls/src/api/mls.rs (2 hunks)
  • xmtp_mls/src/builder.rs (0 hunks)
  • xmtp_mls/src/groups/mod.rs (1 hunks)
  • xmtp_mls/src/groups/subscriptions.rs (14 hunks)
  • xmtp_mls/src/groups/sync.rs (0 hunks)
  • xmtp_mls/src/lib.rs (1 hunks)
  • xmtp_mls/src/subscriptions.rs (9 hunks)
💤 Files with no reviewable changes (2)
  • xmtp_mls/src/builder.rs
  • xmtp_mls/src/groups/sync.rs
🔇 Additional comments (18)
xmtp_mls/src/lib.rs (1)

83-83: LGTM! Improved error message readability.

Using the Display trait ({}) instead of Debug ({:?}) provides more user-friendly error messages, which aligns well with the PR's goal of improving error handling.

bindings_node/src/conversations.rs (1)

216-216: LGTM! Improved error handling in stream callback.

The changes successfully implement proper error propagation through the FFI boundary while maintaining type safety. The error handling chain correctly maps Rust errors to Node.js errors, which aligns well with the PR's objective of passing stream errors through to callbacks.

Also applies to: 220-223

bindings_node/src/groups.rs (1)

78-86: LGTM: Clean implementation of From trait

The implementation correctly handles the conversion from MlsGroup<RustXmtpClient> to NapiGroup, properly transferring all required fields.

xmtp_mls/src/api/mls.rs (2)

5-5: LGTM: Import addition aligns with PR objectives.

The addition of XmtpMlsStreams import supports the enhanced error handling in stream callbacks.


265-265: Verify impact of return type change.

The return type change from generic stream to XmtpMlsStreams::GroupMessageStream improves error handling through FFI, which aligns with the PR objectives. However, this could be a breaking change.

Consider:

  1. Adding documentation to explain the new error handling behavior
  2. Verifying that all XmtpMlsStreams implementations properly handle errors

Let's verify the impact:

✅ Verification successful

Let me gather more information about the trait definition and its implementations to better understand the impact.


Based on the gathered information, I can now provide the final response:

Return type change is safe and well-implemented across the codebase

The change from impl futures::Stream<Item = Result<GroupMessage, ApiError>> + '_ to <ApiClient as XmtpMlsStreams>::GroupMessageStream<'_> is safe because:

  • All implementations of GroupMessageStream consistently use Result<GroupMessage, Error> as the stream item type
  • The trait is properly implemented across different contexts:
    • xmtp_api_http: Uses BoxStream for async contexts
    • xmtp_api_grpc: Has a dedicated GroupMessageStream type
    • Test utilities: Support both BoxStream and LocalBoxStream

The change maintains compatibility while improving type safety and error handling through FFI. No breaking changes are introduced as all implementations follow the same error handling pattern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other implementations and usages that might be affected

# Find all implementations of XmtpMlsStreams
echo "Checking XmtpMlsStreams implementations..."
ast-grep --pattern 'impl $trait for $type {
  $$$
}' | rg 'XmtpMlsStreams'

# Find all direct usages of subscribe_group_messages
echo "Checking subscribe_group_messages usages..."
rg -A 3 'subscribe_group_messages\('

Length of output: 4172


Script:

#!/bin/bash
# Find the XmtpMlsStreams trait definition
echo "Checking XmtpMlsStreams trait definition..."
ast-grep --pattern 'trait XmtpMlsStreams {
  $$$
}'

# Find all type definitions for GroupMessageStream
echo "Checking GroupMessageStream type definitions..."
rg "type GroupMessageStream"

# Find implementations of XmtpMlsStreams specifically
echo "Checking XmtpMlsStreams implementations..."
ast-grep --pattern 'impl XmtpMlsStreams for $type {
  $$$
}'

Length of output: 1368

xmtp_mls/src/groups/mod.rs (2)

230-230: LGTM: New error variants enhance error handling.

The new error variants in GroupError provide clear and specific error messages for DM validation, metadata field validation, and sync operation failures. The error messages follow Rust conventions and are well integrated with the codebase.


230-230: Verify the necessity of exposing the client field.

The visibility change of the client field from pub(crate) to pub is a breaking change that exposes internal implementation details. While this may be necessary for error propagation through callbacks, it could impact encapsulation and make future refactoring more difficult.

Run the following script to verify if this field is actually used outside the crate:

✅ Verification successful

The results show that the client field is indeed being accessed in bindings_node/src/groups.rs, which is outside the xmtp_mls crate. Let me verify if this is part of the intended public API by checking the module structure and documentation.


Let me check the bindings layer more specifically to understand if this is part of the intended public API design.


Based on the evidence gathered, I can now provide a final response:

The pub visibility of the client field is justified

The visibility change from pub(crate) to pub is necessary as the field is legitimately used in the Node.js bindings layer (bindings_node/src/groups.rs). Specifically, it's used in the From implementation that converts MlsGroup to NapiGroup, which is part of the public API bridge to Node.js. This is a valid use case for exposing the field, as bindings layers often need access to internal clients for proper integration.

  • The field is used in bindings_node/src/groups.rs for the Node.js bindings implementation
  • Within the core crate, usage is still controlled and appears in expected locations like subscriptions.rs and intents.rs
  • The visibility change aligns with the codebase's architecture where the bindings layer needs access to core functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for external usage of the client field
# Test: Search for direct access to the client field outside the crate. Expect: No matches outside xmtp_mls.

rg -A 3 'group\.client' --type rust

Length of output: 866


Script:

#!/bin/bash
# Check module documentation and structure
rg -B 3 -A 3 "pub struct MlsGroup" --type rust

# Check if there are any other references to this field in documentation or tests
rg "client.*field" --type rust

Length of output: 383


Script:

#!/bin/bash
# Check the bindings implementation and usage context
rg -B 5 -A 5 "inner_client: mls_group\.client" --type rust

# Check if there are any related tests or documentation
ast-grep --pattern 'pub struct MlsGroup {
  $$$
}'

Length of output: 687

xmtp_mls/src/groups/subscriptions.rs (7)

15-15: Importing SubscribeError for enhanced error handling

The addition of SubscribeError aligns with the new error handling strategy and is appropriate.


25-25: Updated return type in process_stream_entry improves error specificity

Changing the return type to Result<StoredGroupMessage, SubscribeError> enhances error reporting by using a more specific error type.


63-72: Ensure comprehensive error handling in process_stream_entry

Currently, the code handles SubscribeError::Receive(_) by attempting a sync and logs other errors. Consider verifying that all potential SubscribeError variants are appropriately handled to prevent unintended behavior.


114-116: Updated return type in stream method enhances error propagation

Changing the return type to a stream of Result<StoredGroupMessage, SubscribeError> ensures that errors within the stream are properly propagated to the caller.


187-195: Filter logic correctly skips inconsequential errors

The filter appropriately skips over SubscribeError::GroupMessageNotFound errors, preventing unnecessary processing of missing messages.


206-206: Callback signature updated to handle errors effectively

Modifying the callback to accept Result<StoredGroupMessage, SubscribeError> allows for proper error handling within the callback function.


369-369: ⚠️ Potential issue

Check for errors before asserting in tests

Before asserting on the message content, ensure that the Result is Ok to prevent panics.

Apply this diff:

-        .starts_with("hello".as_bytes()));
+    match value {
+        Ok(msg) => assert!(msg.decrypted_message_bytes.starts_with("hello".as_bytes())),
+        Err(e) => panic!("Failed to process message: {:?}", e),
+    }

Likely invalid or redundant comment.

xmtp_mls/src/subscriptions.rs (4)

10-15: Imports updated appropriately

The imports have been updated to include necessary modules for the new error handling implementation.


89-109: Well-structured SubscribeError enum definition

The new SubscribeError enum is defined appropriately, encapsulating all relevant error scenarios for subscription processes.


111-126: Correct implementation of RetryableError for SubscribeError

The implementation correctly determines the retryable nature of each SubscribeError variant.


248-250: Callback signature updated to enhance error handling

The stream_conversations_with_callback function now passes Result<MlsGroup<Self>, SubscribeError> to the callback, enhancing error handling capabilities.

@insipx insipx force-pushed the insipx/stream-error-callbacks branch from 9fd8190 to 500e6c6 Compare October 24, 2024 21:37
@insipx insipx force-pushed the insipx/stream-error-callbacks branch from 326184f to 63fddda Compare October 25, 2024 15:58
@insipx insipx marked this pull request as ready for review October 25, 2024 16:06
@insipx insipx requested a review from a team as a code owner October 25, 2024 16:06
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (5)
bindings_ffi/src/lib.rs (1)

49-53: Architecture looks good for error propagation.

The new FfiSubscribeError type is well-structured for FFI compatibility and aligns with the PR's objective of passing stream errors through callbacks. The use of uniffi::Error and thiserror ensures proper error handling across language boundaries.

Cargo.toml (2)

Line range hint 65-78: Review the implications of new dependencies.

Several significant additions and changes:

  1. The tracing setup with release_max_level_debug could impact production performance
  2. The diesel ecosystem integration suggests new database functionality
  3. Vendored OpenSSL dependencies ensure build consistency but increase bundle size

Consider:

  • Documenting the logging level configuration for different environments
  • Adding migration guides for the new database functionality
  • Evaluating the impact of vendored dependencies on binary size

Line range hint 107-134: Profile configurations are well-optimized.

The profile settings show careful consideration of different build targets:

  • Incremental builds in release mode can speed up development
  • Binary size optimizations for WASM and node bindings
  • LTO enabled where appropriate

Consider documenting the performance implications of these profile settings, especially:

  • The impact of opt-level = "s" vs "z" on different targets
  • The tradeoffs of enabling incremental builds in release mode
xmtp_mls/src/groups/subscriptions.rs (2)

71-72: Enhance error logging message

The error message could be more descriptive to aid in debugging.

Apply this diff:

-                tracing::error!("Process stream entry {:?}", e);
+                tracing::error!("Failed to process stream entry: {:?}", e);

Line range hint 1-428: Overall implementation looks solid

The changes successfully implement error propagation through callbacks, which was the main objective of this PR. The implementation includes:

  • Proper error type handling
  • Appropriate error logging
  • Consistent error propagation through streams and callbacks

The code structure is clean and maintainable.

Consider documenting the error handling behavior in the module-level documentation to help users understand how to properly handle errors in their callbacks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9fd8190 and 57a9c0d.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • bindings_wasm/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • .vscode/settings.json (1 hunks)
  • Cargo.toml (2 hunks)
  • bindings_ffi/Cargo.toml (2 hunks)
  • bindings_ffi/Makefile (1 hunks)
  • bindings_ffi/gen_kotlin.sh (1 hunks)
  • bindings_ffi/src/lib.rs (1 hunks)
  • bindings_ffi/src/mls.rs (39 hunks)
  • bindings_node/src/conversations.rs (7 hunks)
  • bindings_node/src/groups.rs (2 hunks)
  • dev/release-kotlin (1 hunks)
  • xmtp_mls/src/builder.rs (0 hunks)
  • xmtp_mls/src/groups/mod.rs (1 hunks)
  • xmtp_mls/src/groups/subscriptions.rs (13 hunks)
  • xmtp_mls/src/groups/sync.rs (0 hunks)
  • xmtp_mls/src/lib.rs (1 hunks)
  • xmtp_mls/src/subscriptions.rs (17 hunks)
💤 Files with no reviewable changes (2)
  • xmtp_mls/src/builder.rs
  • xmtp_mls/src/groups/sync.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • .vscode/settings.json
  • bindings_node/src/conversations.rs
  • xmtp_mls/src/lib.rs
🔇 Additional comments (17)
dev/release-kotlin (1)

35-37: LGTM! Clean directory management logic.

The directory cleanup and movement operations are well-structured:

  1. Removes the existing jniLibs directory to prevent stale artifacts
  2. Moves the newly generated libraries to the target location
bindings_ffi/gen_kotlin.sh (1)

21-21: LGTM! Build command is now more specific

The build command now explicitly targets the xmtpv3 package, which improves clarity and efficiency.

bindings_ffi/Cargo.toml (2)

16-16: LGTM! Good optimization of uniffi features.

Moving the "cli" feature out of the main dependency is a good practice. This ensures the CLI tools are only included when actually needed for binding generation, reducing unnecessary dependencies in the main library.


31-32: LGTM! Well-structured binary configuration.

The changes to the binary configuration are well thought out:

  • Moving binding generation code to a dedicated bindgen directory improves organization
  • Adding required-features = ["uniffi/cli"] ensures CLI tools are only included when needed for binding generation
bindings_ffi/Makefile (1)

Line range hint 86-90: LGTM! Build process improvement.

The updated command for generating Swift bindings is an improvement as it:

  • Ensures the binary is built with the correct features through explicit --features uniffi/cli flag
  • Follows cargo's recommended practices by using cargo run
  • Provides a more reliable and self-contained build process
Cargo.toml (1)

62-63: Verify tonic version change impact on mobile platforms.

The change from ^0.12.2 to 0.12 is more restrictive. As noted in the comment, this could affect iOS/Android builds.

Please ensure:

  1. The build works correctly on both iOS and Android platforms
  2. TLS functionality remains intact across all platforms

Consider documenting the mobile platform testing requirements in the project's contribution guidelines.

bindings_node/src/groups.rs (2)

78-86: LGTM! Clean implementation of From trait

The implementation correctly maps all necessary fields from MlsGroup to NapiGroup, providing a safer and more idiomatic way to perform the conversion.


561-567: LGTM! Improved error handling in stream callback

The implementation now properly propagates errors through the FFI boundary to Node.js callbacks, aligning with the PR objectives. The error conversion chain is well-structured and type-safe.

Note: The use of ThreadsafeFunctionCallMode::Blocking might impact performance under high message volumes. Consider documenting the rationale for choosing blocking mode over non-blocking.

Let's verify the usage of blocking mode in other stream implementations:

xmtp_mls/src/groups/subscriptions.rs (1)

369-372: LGTM with a note about test assertions

The test assertions look correct, but consider addressing the unwrap-related suggestions from previous reviews to improve test robustness.

xmtp_mls/src/subscriptions.rs (2)

89-126: Well-structured error handling implementation!

The new SubscribeError enum is well-designed with:

  • Clear and descriptive error variants
  • Proper error conversion using #[from]
  • Good implementation of RetryableError trait for retry logic

192-217: Good error propagation in stream functions!

The modifications correctly implement error handling in streams:

  • Proper return type using Result<_, SubscribeError>
  • Well-structured error handling in filter_group closure
  • Correct stream composition with error propagation
xmtp_mls/src/groups/mod.rs (3)

230-230: LGTM: New error variants enhance error handling.

The new error variants InvalidDmMissingInboxId, MissingMetadataField, and SyncFailedToWait are well-defined and provide clear error messages. They improve error handling by making specific failure cases more identifiable.


230-230: LGTM: Robust error handling implementation.

The error handling implementation is comprehensive with proper error propagation through the RetryableError trait. The code correctly handles various error scenarios including retryable errors.


230-230: Verify the impact of making client field public.

The visibility change of the client field from pub(crate) to pub is a breaking change that exposes internal implementation details. Please ensure this change is necessary for error propagation and doesn't break encapsulation principles.

bindings_ffi/src/mls.rs (3)

1175-1179: Ensure consistent error mapping to FfiSubscribeError

The method process_streamed_conversation_message now returns Result<FfiMessage, FfiSubscribeError>. Please verify that all errors from self.inner.process_streamed_group_message are correctly mapped to FfiSubscribeError, ensuring consistent error handling and that no errors are unhandled or improperly converted.


844-846: Handle possible integer conversion errors

The conversion of num_groups_synced to u32 includes error handling with map_err(|_| GenericError::FailedToConvertToU32). This ensures that any potential TryInto conversion errors are properly managed and propagated.


1322-1325: Consistent error handling in admin list updates

The methods add_admin, remove_admin, add_super_admin, and remove_super_admin use map_err(Into::into) to handle errors from self.inner.update_admin_list. Verify that the error conversion is appropriate and that errors are correctly mapped to the expected error types.

Also applies to: 1329-1332, 1336-1339, 1343-1346

insipx and others added 3 commits October 25, 2024 12:23
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@insipx insipx requested a review from richardhuaaa October 25, 2024 16:45
@@ -1799,14 +1575,16 @@ impl FfiStreamCloser {
}
}

#[uniffi::export(callback_interface)]
#[uniffi::export(with_foreign)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callback_interface was deprecated

@insipx insipx requested review from nplasterer and removed request for richardhuaaa and nplasterer October 25, 2024 19:12
@insipx insipx merged commit d1d33e3 into main Oct 25, 2024
17 checks passed
@insipx insipx deleted the insipx/stream-error-callbacks branch October 25, 2024 21:41
insipx added a commit that referenced this pull request Oct 29, 2024
* Callbacks now take a Result<T>
* Add `on_error` to ffi

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Feature request: Pass stream errors through to callbacks
2 participants