fix(feishu): resolve compilation errors in Feishu/Lark WASM channel (#1200)#1204
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical compilation errors within the Feishu/Lark WASM channel. The changes primarily involve updating macro usage, correcting function argument types to align with WIT-generated bindings, and refining data structures for proper serialization. These fixes ensure the channel can compile successfully and operate as intended, improving the stability and maintainability of the Feishu integration. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
…earai#1200) The Feishu channel WASM crate could not be compiled due to mismatches with the WIT-generated bindings. - Replace nonexistent export_sandboxed_channel! with export! macro - Fix http_request body arg: &String -> .as_bytes() for Option<&[u8]> - Fix pairing_is_allowed arg: &String -> Some(&str) for Option<&str> - Fix emit_message arg: pass &EmittedMessage instead of owned value - Add Default derive to TenantAccessTokenData for serde deserialization - Remove unused imports (Attachment, PollConfig) - Track Cargo.lock consistent with other channel crates [skip-regression-check]
8e55f92 to
b92c8a8
Compare
There was a problem hiding this comment.
Code Review
The pull request updates the Cargo.lock file and refactors the feishu-channel Rust code. Key changes include removing unused types (Attachment, PollConfig), updating the channel export macro, and making various formatting improvements. A notable change is the modification of http_request calls to pass JSON request bodies as byte arrays, which is an improvement for performance and robustness, as suggested by a reviewer, who recommended using serde_json::to_vec for direct serialization to a byte vector to reduce allocations and handle serialization errors gracefully.
| let body_bytes = body.to_string(); | ||
| let result = channel_host::http_request( | ||
| "POST", | ||
| &url, | ||
| &headers.to_string(), | ||
| Some(&body.to_string()), | ||
| Some(body_bytes.as_bytes()), | ||
| Some(10_000), | ||
| ); |
There was a problem hiding this comment.
For consistency and slightly better performance, you can serialize the JSON body directly to a byte vector using serde_json::to_vec. It's recommended to handle potential serialization errors gracefully with map_err for robustness, similar to other serialization calls.
| let body_bytes = body.to_string(); | |
| let result = channel_host::http_request( | |
| "POST", | |
| &url, | |
| &headers.to_string(), | |
| Some(&body.to_string()), | |
| Some(body_bytes.as_bytes()), | |
| Some(10_000), | |
| ); | |
| let body_bytes = serde_json::to_vec(&body).map_err(|e| format!("Failed to serialize body: {}", e))?; | |
| let result = channel_host::http_request( | |
| "POST", | |
| &url, | |
| &headers.to_string(), | |
| Some(&body_bytes), | |
| Some(10_000), | |
| ); |
References
- To improve performance in WASM, avoid unnecessary heap allocations. Serializing directly to a byte vector (
Vec<u8>) instead of an intermediateStringreduces allocations and avoids redundant UTF-8 validation, which is beneficial for WASM.
zmanian
left a comment
There was a problem hiding this comment.
Review: APPROVE
Clean, tightly-scoped compilation fix. All 7 compiler errors from #1200 resolved with correct mechanical fixes:
- Fixed macro:
export_sandboxed_channel!->export! - Fixed
http_requestbody type:Some(&body_json)->Some(body_json.as_bytes())forOption<&[u8]>(3 call sites) - Fixed
pairing_is_allowedarg:&sender_name->Some(&sender_name)forOption<&str> - Fixed
emit_message: pass by reference - Added
Defaultderive toTenantAccessTokenData(required by serde) - Removed unused imports (
Attachment,PollConfig) - Added
Cargo.lock(matches convention for other channel crates)
No .unwrap() in production code. CI all green.
Minor nit (non-blocking): body_bytes variable at line ~754 holds a String, not bytes -- body_str would be a more accurate name.
Safe to merge.
Code reviewNo issues found. |
…earai#1200) (nearai#1204) Resolve compilation errors in Feishu/Lark WASM channel
…earai#1200) (nearai#1204) Resolve compilation errors in Feishu/Lark WASM channel
Summary
The Feishu channel WASM crate could not be compiled due to mismatches
with the WIT-generated bindings.
Change Type
Linked Issue
Closes #1200
Validation
cargo fmtcargo clippy --all --benches --tests --examples --all-featuresSecurity Impact
Database Impact
Blast Radius
Rollback Plan
Review track: