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
Package#fetch_readmecurrently assumes the full nested repo metadata shape exists:If
repo_metadatais present but missingmetadata,files, orreadme, this raises and is swallowed by the broad rescue, returningnil.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: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