Skip to content

refactor(cargo): improve lock parse error context and remove dead null-guards - #622

Merged
Strum355 merged 2 commits into
guacsec:mainfrom
a-oren:TC-5729
Aug 31, 2026
Merged

refactor(cargo): improve lock parse error context and remove dead null-guards#622
Strum355 merged 2 commits into
guacsec:mainfrom
a-oren:TC-5729

Conversation

@a-oren

@a-oren a-oren commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add lock file path and error message to the parseCargoLockHashes catch block for descriptive diagnostics (per CONVENTIONS.md error-handling guidance).
  • Remove dead hashMap null-guards in addTransitiveDeps and addDirectDepsparseCargoLockHashes always returns a Map, so all three call sites now use consistent direct .get() access.
  • Add a test covering the malformed Cargo.lock warning (asserts path + error detail in console.warn).

Testing

  • npm test -- test/providers/rust_cargo.test.js — 74 passing.

Implements TC-5729

Summary by Sourcery

Improve Cargo.lock parsing diagnostics and simplify dependency hash handling.

Enhancements:

  • Improve Cargo.lock parse warnings with the file path and underlying error details.
  • Remove unnecessary null guards when retrieving Cargo dependency hashes.

Tests:

  • Add coverage for malformed Cargo.lock warnings, including the path and error message.

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes Cargo.lock parse failures actionable by reporting the file path and underlying parser error, adds regression coverage with a malformed lock fixture, and simplifies dependency hash lookups around the guaranteed Map return value.

Sequence diagram for Cargo.lock parse failure diagnostics

sequenceDiagram
    participant CargoProvider
    participant CargoLockParser
    participant Console
    CargoProvider->>CargoLockParser: parseCargoLockHashes(manifestDir, opts)
    CargoLockParser-->>CargoProvider: Map or parse error
    alt malformed Cargo.lock
        CargoLockParser->>Console: console.warn(lockPath, error.message)
        CargoLockParser-->>CargoProvider: hashMap
        CargoProvider->>CargoProvider: Generate SBOM without hashes
    end
Loading

Flow diagram for Cargo dependency hash lookup

flowchart LR
    Parse["parseCargoLockHashes returns Map"] --> Direct["addDirectDeps calls hashMap.get()"]
    Parse --> Transitive["addTransitiveDeps calls hashMap.get()"]
    Direct --> SBOM["sbom.addDependency with hashes"]
    Transitive --> SBOM
Loading

File-Level Changes

Change Details Files
Improves malformed Cargo.lock diagnostics by including the lock file path and parser error detail in the warning while preserving hash parsing fallback behavior.
  • Expands the parse failure warning with the lock path, error message, and explicit no-hashes consequence.
  • Adds a malformed lock fixture and verifies the warning contains the expected path, error context, and fallback text.
src/providers/rust_cargo.js
test/providers/rust_cargo.test.js
test/providers/tst_manifests/cargo/cargo_malformed_lock_test/Cargo.lock
test/providers/tst_manifests/cargo/cargo_malformed_lock_test/Cargo.toml
test/providers/tst_manifests/cargo/cargo_malformed_lock_test/cargo_metadata.json
Removes redundant null checks from dependency hash lookups based on the invariant that lock hash parsing always returns a Map.
  • Uses direct Map.get() access for transitive and direct dependency hash resolution.
  • Keeps dependency generation behavior unchanged when a package has no matching hash.
src/providers/rust_cargo.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Aug 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.45%. Comparing base (b77d624) to head (7c42c0c).

Files with missing lines Patch % Lines
src/providers/rust_cargo.js 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #622   +/-   ##
=======================================
  Coverage   91.45%   91.45%           
=======================================
  Files          44       44           
  Lines       10172    10172           
  Branches     1840     1838    -2     
=======================================
  Hits         9303     9303           
  Misses        869      869           
Flag Coverage Δ
unit-tests 91.45% <66.66%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/providers/rust_cargo.js 97.37% <66.66%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Strum355 Strum355 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would personally remove the malformed lock test. Feels like a case of Claude being overzealous with adding tests for the tiniest things

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

a-oren added 2 commits August 31, 2026 18:37
…l-guards

Add lock file path and error message to the parseCargoLockHashes catch
block for descriptive diagnostics, and remove the dead hashMap null-guards
in addTransitiveDeps and addDirectDeps (parseCargoLockHashes always
returns a Map). Add a test covering the malformed Cargo.lock warning.

Implements TC-5729

Assisted-by: Claude Code
@Strum355
Strum355 merged commit 071e51e into guacsec:main Aug 31, 2026
4 checks passed
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.

3 participants