From c63c8a16e60a70475a93d33e5f0e2531c1b01251 Mon Sep 17 00:00:00 2001 From: Vlad-Stefan Harbuz Date: Tue, 12 Sep 2023 17:33:20 +0100 Subject: [PATCH] fix: tolerate null bugs URLs 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: /~https://github.com/npm/hosted-git-info/pull/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/. --- lib/commands/bugs.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/commands/bugs.js b/lib/commands/bugs.js index 17cbd96649b87..bb8b705ba47ea 100644 --- a/lib/commands/bugs.js +++ b/lib/commands/bugs.js @@ -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!