Skip to content

fix(verify): wrong exception type caught — verification crashes on missing content #30

Description

@aliangm

verify_source() catches FileNotFoundError but store.read_source_content() raises ArtifactNotFoundError (a KeyError subclass) when content is missing. The mismatch means a single source with missing content crashes the entire verification sweep.

Bug

  • File: src/vouch/verify.py:30-31
  • Buggy code:
def verify_source(store: KBStore, source: Source) -> VerificationResult:
    try:
        body = store.read_source_content(source.id)
    except FileNotFoundError:  # <-- wrong exception type
        return VerificationResult(source=source, stored_ok=False,
                                  external_status="n/a", note="stored content missing")
  • Correct pattern (from storage.py:217-221):
def read_source_content(self, source_id: str) -> bytes:
    p = self._source_dir(source_id) / "content"
    if not p.exists():
        raise ArtifactNotFoundError(f"source content {source_id}")  # KeyError subclass
    return p.read_bytes()

Steps to Reproduce

  1. vouch init && vouch source add some-file.txt (registers a source)
  2. Manually delete .vouch/sources/<sha256>/content
  3. Run vouch source verify or vouch doctor
  4. Result: unhandled ArtifactNotFoundError traceback instead of graceful "stored content missing" report

Expected Behavior

verify_source should catch ArtifactNotFoundError and return a VerificationResult with stored_ok=False, as the code clearly intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions