Skip to content

Package#fetch_readme should handle partial repo_metadata without relying on rescue #1695

Description

@abhinavgautam01

Package#fetch_readme currently assumes the full nested repo metadata shape exists:

repo_metadata['metadata']['files']['readme']

If repo_metadata is present but missing metadata, files, or readme, this raises and is swallowed by the broad rescue, returning nil.

That makes missing/partial metadata look like an exception path instead of a normal no-readme case. It also hides malformed metadata and makes the method harder to reason about.

This can be handled directly with dig:

readme = repo_metadata.dig("metadata", "files", "readme")
return if readme.blank?

The current broad rescue already prevents the exception from escaping, this is just for cleanup/robustness rather than a user-facing crash.

Relevant code:

  • app/models/package.rb#fetch_readme

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions