Skip to content

Commit

Permalink
fix: tolerate null bugs URLs
Browse files Browse the repository at this point in the history
Currently, if the bugs URL returned from `package.json`, which is
processed through
[hosted-git-info](https://github.com/npm/hosted-git-info), is falsy, an
error is thrown. However, hosted-git-info may well return a falsy bugs
URL. This can happen when there is no bugs URL in the repo, but
hosted-git-info tries to infer one, but one cannot be inferred, for
example if the repository URL is a SourceHut URL. This is described
here: npm/hosted-git-info#213

For this reason, we should tolerate falsy URLs and fall back to whatever
is defined in `bugs.js`, in this case being sent to
https://www.npmjs.com/package/<packageName>.
  • Loading branch information
vladh committed Sep 12, 2023
1 parent 6ec6ff0 commit c63c8a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/commands/bugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class Bugs extends PackageUrlCmd {
// try to get it from the repo, if possible
const info = this.hostedFromMani(mani)
if (info) {
return info.bugs()
const infoUrl = info.bugs();
if (infoUrl) {
return infoUrl;
}
}

// just send them to the website, hopefully that has some info!
Expand Down

0 comments on commit c63c8a1

Please sign in to comment.