Skip to content

Commit 0c8c643

Browse files
authored
Improve error message when GitHub API rate limit is exceeded during license fetching (#590)
1 parent d9d9f38 commit 0c8c643

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
`summoner` uses [PVP Versioning][1].
44
The changelog is available [on GitHub][2].
55

6+
# Unreleased
7+
8+
* [#589](https://github.com/kowainik/summoner/issues/589):
9+
Improve error message when GitHub API rate limit is exceeded during license fetching.
10+
611
# 2.2.0.0 – Jan 16, 2026
712

813
* [#560](https://github.com/kowainik/summoner/issues/560):

summoner-cli/src/Summoner/License.hs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module Summoner.License
2222
, showLicenseWithDesc
2323
) where
2424

25-
import Colourista (errorMessage)
25+
import Colourista (errorMessage, infoMessage, warningMessage)
26+
import Control.Exception (try)
2627
import Data.Aeson.Micro (FromJSON (..), decodeStrict, withObject, (.:))
2728
import Shellmet (($|))
2829

@@ -106,18 +107,29 @@ fetchLicense :: LicenseName -> IO License
106107
fetchLicense NONE = pure $ License $ licenseShortDesc NONE
107108
fetchLicense name = do
108109
let licenseLink = "https://api.github.com/licenses/" <> githubLicenseQueryNames name
109-
licenseJson <- "curl" $|
110+
curlResult <- try @SomeException $ "curl" $|
110111
[ licenseLink
111112
, "-H"
112113
, "Accept: application/vnd.github.drax-preview+json"
113114
, "--silent"
114115
, "--fail"
115116
]
116117

117-
whenNothing (decodeStrict @License $ encodeUtf8 licenseJson) $ do
118-
errorMessage $ "Error downloading license: " <> show name
119-
putTextLn $ "Fetched content:\n" <> licenseJson
120-
exitFailure
118+
case curlResult of
119+
Left _ -> do
120+
errorMessage $ "Error fetching license: " <> show name
121+
warningMessage "The GitHub API rate limit may have been exceeded."
122+
warningMessage "This can happen when using a VPN or a shared network."
123+
infoMessage "Possible workarounds:"
124+
infoMessage " * Wait a few minutes and try again"
125+
infoMessage " * Try from a different network (e.g. disable VPN)"
126+
infoMessage " * Choose the 'NONE' license and add the LICENSE file manually"
127+
exitFailure
128+
Right licenseJson ->
129+
whenNothing (decodeStrict @License $ encodeUtf8 licenseJson) $ do
130+
errorMessage $ "Error downloading license: " <> show name
131+
putTextLn $ "Fetched content:\n" <> licenseJson
132+
exitFailure
121133

122134
{- | Fetches the license by given name and customises user information where
123135
applicable.

0 commit comments

Comments
 (0)