Conversation
Parse untyped JSON first so we surface API error messages instead of decode failures.
Reviewer's GuideImproves error handling in GraphQLClient by returning API errors immediately, using an intermediate serde_json::Value for response data, preserving the original request context, and mapping JSON decoding failures to a unified BadResponseSerde error variant. Sequence diagram for improved GraphQLClient error handlingsequenceDiagram
participant Client as GraphQLClient
participant HTTP as HTTP Server
participant VkError
Client->>HTTP: POST GraphQL query
HTTP-->>Client: JSON response
alt Response contains errors
Client->>VkError: handle_graphql_errors(errors)
Client-->>Client: Return VkError::ApiErrors
else Response contains data
Client->>Client: serde_json::from_value(data)
alt Decoding fails
Client->>VkError: BadResponseSerde(error)
Client-->>Client: Return VkError::BadResponseSerde
else Decoding succeeds
Client-->>Client: Return Ok(result)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary by CodeRabbit
WalkthroughUpdate the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.rs📄 CodeRabbit Inference Engine (AGENTS.md)
Files:
⚙️ CodeRabbit Configuration File
Files:
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/main.rs:179` </location>
<code_context>
- resp.data.ok_or(VkError::BadResponse)
+
+ let value = resp.data.ok_or(VkError::BadResponse)?;
+ serde_json::from_value(value).map_err(|_| VkError::BadResponse)
}
}
</code_context>
<issue_to_address>
Mapping all deserialization errors to VkError::BadResponse may lose error context.
Consider preserving the original serde_json::from_value error message in VkError::BadResponse or another error variant to improve debugging and troubleshooting.
Suggested implementation:
```rust
let value = resp.data.ok_or(VkError::BadResponse)?;
serde_json::from_value(value).map_err(|e| VkError::BadResponseSerde(e.to_string()))
```
1. Update the `VkError` enum definition to add a new variant:
```rust
VkError::BadResponseSerde(String)
```
2. Update any error handling or matching logic elsewhere in the codebase that expects only `VkError::BadResponse` to also handle `VkError::BadResponseSerde`.
3. Optionally, implement `Display`/`Error` for the new variant if not already handled.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/main.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit Inference Engine (AGENTS.md)
**/*.rs: Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not usereturnin single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Prefer immutable data and avoid unnecessarymutbindings.
Handle errors with theResulttype instead of panicking where feasible.
Prefer semantic error enums: Derivestd::error::Error(via thethiserrorcrate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Useeyre::Reportfor human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and toeyreonly in the mainmain()entrypoint or top-level async task.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider usingArcto reduce the amount of data returned.
Write unit and behavioural tests for new functionality. Run both before and after making any change.
Avoidunsafecode unless absolutely necessary and document any usage clearly.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Preferexpectoverallow.
Prefer.expect()over.unwrap().
Useconcat!()to combine long string literals rather than escaping newlines with a backslash.
Files:
src/main.rs
⚙️ CodeRabbit Configuration File
**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.
Adhere to single responsibility and CQRS
Place function attributes after doc comments.
Do not use
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless absolutely necessary.Every module must begin with a
//!doc comment that explains the module's purpose and utility.Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar
Lints must not be silenced except as a last resort.
#[allow]is forbidden.- Only narrowly scoped
#[expect(lint, reason = "...")]is allowed.- No lint groups, no blanket or file-wide suppression.
- Include
FIXME:with link if a fix is expected.Use
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor mocks/stubs.Prefer
.expect()over.unwrap()Ensure that any API or behavioural changes are reflected in the documentation in
docs/Ensure that any completed roadmap steps are recorded in the appropriate roadmap in
docs/Files must not exceed 400 lines in length
- Large modules must be decomposed
- Long match statements or dispatch tables should be decomposed by domain and collocated with targets
- Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
Files:
src/main.rs
🔇 Additional comments (2)
src/main.rs (2)
156-156: Approve the intermediate deserialization approach.The change to deserialize into
GraphQlResponse<serde_json::Value>correctly implements the first step of the two-step process, allowing error handling before final type conversion.
170-170: Correct ownership handling in error paths.Cloning the context string ensures both error branches can access it without violating Rust's ownership rules.
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/main.rs:180` </location>
<code_context>
}
- resp.data.ok_or(VkError::BadResponse)
+
+ let value = resp.data.ok_or(VkError::BadResponse)?;
+ serde_json::from_value(value).map_err(|e| VkError::BadResponseSerde(e.to_string()))
}
</code_context>
<issue_to_address>
Error variant for missing data may not provide enough context.
Consider including relevant response details in VkError::BadResponse to improve debugging.
Suggested implementation:
```rust
let value = resp.data.ok_or_else(|| {
VkError::BadResponse(format!("Missing data in response: {:?}", resp))
})?;
serde_json::from_value(value).map_err(|e| VkError::BadResponseSerde(e.to_string()))
```
1. You must update the definition of `VkError::BadResponse` to accept a `String` (or other suitable type) for context, e.g.:
```rust
BadResponse(String)
```
2. Update all other usages and match arms for `VkError::BadResponse` to handle the new parameter.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary
Testing
make fmtmake lintmake testmake markdownlintmake nixie(fails: too many arguments)https://chatgpt.com/codex/tasks/task_e_688624cb2988832297046de8f7b8405e
Summary by Sourcery
Improve GraphQLClient error handling by deferring data decoding until after checking for API errors and exposing decoding failures with a new error variant
Bug Fixes:
Enhancements: