Report AI models requested via OpenRouter and Vercel API's#458
Report AI models requested via OpenRouter and Vercel API's#458reiniercriel wants to merge 4 commits into
Conversation
| let parsed: AggregatorRequestModel = serde_json::from_slice(bytes) | ||
| .inspect_err(|err| { | ||
| tracing::debug!( | ||
| error = %err, | ||
| "failed to parse openrouter request body as JSON with `model`" | ||
| ); | ||
| }) | ||
| .ok()?; |
There was a problem hiding this comment.
The parse_model_field implementation combines serde_json::from_slice, inspect_err with a closure containing tracing::debug!, and .ok()? on a single expression. Split parsing, error logging, and the optional conversion into clearer steps.
Show fix
| let parsed: AggregatorRequestModel = serde_json::from_slice(bytes) | |
| .inspect_err(|err| { | |
| tracing::debug!( | |
| error = %err, | |
| "failed to parse openrouter request body as JSON with `model`" | |
| ); | |
| }) | |
| .ok()?; | |
| let parse_result = serde_json::from_slice(bytes); | |
| if let Err(err) = &parse_result { | |
| tracing::debug!( | |
| error = %err, | |
| "failed to parse openrouter request body as JSON with `model`" | |
| ); | |
| } | |
| let parsed: AggregatorRequestModel = parse_result.ok()?; |
Details
✨ AI Reasoning
The code attempts to parse JSON from a byte slice and logs parsing errors using an inline closure inside a chained call. This packs parsing, error inspection with a closure containing a tracing call, and immediate .ok()? conversion onto a single expression, increasing cognitive load when reviewing error flow and return semantics.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
| let parsed: AggregatorRequestModel = serde_json::from_slice(bytes) | ||
| .inspect_err(|err| { | ||
| tracing::debug!( | ||
| error = %err, | ||
| "failed to parse vercel-ai-gateway request body as JSON with `model`" | ||
| ); | ||
| }) | ||
| .ok()?; |
There was a problem hiding this comment.
The parse_model_field implementation chains serde_json::from_slice, inspect_err with a logging closure, and .ok()? on one expression. Separate parsing, error logging, and optional handling into distinct statements.
Show fix
| let parsed: AggregatorRequestModel = serde_json::from_slice(bytes) | |
| .inspect_err(|err| { | |
| tracing::debug!( | |
| error = %err, | |
| "failed to parse vercel-ai-gateway request body as JSON with `model`" | |
| ); | |
| }) | |
| .ok()?; | |
| let parse_result = serde_json::from_slice(bytes); | |
| if let Err(err) = &parse_result { | |
| tracing::debug!( | |
| error = %err, | |
| "failed to parse vercel-ai-gateway request body as JSON with `model`" | |
| ); | |
| } | |
| let parsed: AggregatorRequestModel = parse_result.ok()?; |
Details
✨ AI Reasoning
The code attempts JSON parsing and error logging in a single chained expression: serde_json::from_slice(...).inspect_err(|err| tracing::debug!(...)).ok()?. This bundles parsing, an inline error-inspecting closure that logs details, and immediate ? conversion, making the control flow harder to follow at a glance.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
Summary by Aikido
🚀 New Features
More info