deno
1c5a7189 - fix(audit): gracefully handle malformed response (#32234)

Commit
250 days ago
fix(audit): gracefully handle malformed response (#32234) Fixes an issue where `deno audit` fails to deserialize npm registry responses when the `actions` field is missing. ## Changes Made - Added `#[serde(default)]` attribute to the `actions` field in `AuditResponse` struct in `cli/tools/pm/audit.rs` - this makes the field default to an empty `Vec` when missing from the JSON response - Added a unit test to verify the deserialization works when `actions` field is missing ## Fix Details The issue was that the npm registry audit API response sometimes doesn't include the `actions` field. The Deno audit code was expecting this field to always be present, causing deserialization to fail with: `missing field 'actions' at line 1 column 33` The fix adds `#[serde(default)]` to the `actions` field, which makes it default to an empty vector when the field is not present in the JSON response. This is the standard serde pattern for optional fields that should have a sensible default value. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>`deno audit` fails to deserialize npm registry response</issue_title> > <issue_description>Version: Deno 2.6.10 > > error: Failed to deserialize response from the npm registry API > > Caused by: > missing field `actions` at line 1 column 33</issue_description> > > <agent_instructions>Update `AuditResponse` struct to have `actions` field be optional and default to empty vector. Add a test case for it, you can update test server in `tests/util/server/servers/npm_registry.rs` with relevant fixutre</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes denoland/deno#32233 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bartlomieju <13602871+bartlomieju@users.noreply.github.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: dsherret <1609021+dsherret@users.noreply.github.com>
Author
Parents
Loading