Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error logging when fetching the license from GitHub #382

Closed
ShrykeWindgrace opened this issue Nov 19, 2019 · 4 comments · Fixed by #388
Closed

Improve error logging when fetching the license from GitHub #382

ShrykeWindgrace opened this issue Nov 19, 2019 · 4 comments · Fixed by #388
Assignees
Labels

Comments

@ShrykeWindgrace
Copy link
Contributor

ShrykeWindgrace commented Nov 19, 2019

Hey!
While creating a new project (via either summon or summon-tui), after filling in all required fields, I get

summon: Broken predefined license list
CallStack (from HasCallStack):
  error, called at src/Relude/Debug.hs:204:11 in relude-0.6.0.0-AcrVfUNryj1HsmpcUfIeuY:Relude.Debug
  error, called at src/Summoner/License.hs:109:23 in summoner-1.3.0.1-Oct5iTUxJdB7HF1dRW4f2:Summoner.License

I use the default (MIT) license.

Config: Ubuntu 18.04 with

$ summon --version
Summoner v1.3.0.1
 ➤ Git revision: 0f85356deea738e44425694d939bbadfcd1875a7
 ➤ Commit date:  Sat Nov 9 13:40:45 2019 +0400

and

$ bat -p ~/.summoner.toml
owner    = "ShrykeWindgrace"
fullName = "Full Name"
email    = "myemail@mydomain.email"
ghcVers  = ["8.6.5"]
stack    = true
cabal    = false
lib      = true
bench    = false
@ShrykeWindgrace
Copy link
Contributor Author

Rebuilt the executables with eitherDecodeStrict instead of decodeStrict, got the error

Error in $: key "body" not present

@chshersh
Copy link
Contributor

Hi @ShrykeWindgrace, some possibilities why this can happen — you either didn't have access to the Internet at the moment of creating the project or this particular website is blocked for you or GitHub was broken at that particular moment. I just tried to create a project from your config and it did work for me. I also see the valid content here:

Do you see this error consistently? Do you have curl installed locally? What does the following command produce on your machine?

curl https://api.github.com/licenses/mit -H "Accept: application/vnd.github.drax-preview+json"

@chshersh chshersh added the question Ideas, discussions label Nov 19, 2019
@ShrykeWindgrace
Copy link
Contributor Author

Hi @ShrykeWindgrace, some possibilities why this can happen — you either didn't have access to the Internet at the moment of creating the project or this particular website is blocked for you or GitHub was broken at that particular moment.

Quite a lot of stuff can go wrong =)

Do you see this error consistently?

Yes, more often than not (3 failures out of 4 tries).

Do you have curl installed locally?

I do.

What does the following command produce on your machine?

curl https://api.github.com/licenses/mit -H "Accept: application/vnd.github.drax-preview+json"

The output seems to be ok:

{
  "key": "mit",
  "name": "MIT License",
  "spdx_id": "MIT",
  "url": "https://api.github.com/licenses/mit",
  "node_id": "MDc6TGljZW5zZTEz",
  "html_url": "http://choosealicense.com/licenses/mit/",
  "description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.",
  "implementation": "Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders.",
  "permissions": [
    "commercial-use",
    "modifications",
    "distribution",
    "private-use"
  ],
  "conditions": [
    "include-copyright"
  ],
  "limitations": [
    "liability",
    "warranty"
  ],
  "body": "MIT License\n\nCopyright (c) [year] [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
  "featured": true
}

Given the number of things that could go wrong (as you listed above), and that some of these things are independent of summon and possibly related to the user's environment, I would consider enumerating them in the "failure" branch of fromMaybe. Or even switching to eitherDecodeStrict to additionally recover parsing errors from aeson, but that's to be discussed (I deem the api of github to be rather stable to reply with a valid json all the time).

@chshersh chshersh changed the title Fails to create a new project Improve error logging when fetching the license from GitHub Nov 19, 2019
@chshersh chshersh added Git/Hub VCS issues refactoring and removed question Ideas, discussions labels Nov 19, 2019
@chshersh chshersh added this to the v1.4: Polishment and update milestone Nov 19, 2019
@chshersh
Copy link
Contributor

@ShrykeWindgrace I've never experienced this error before, and nobody has reported it before. So fromMaybe worked well so far. I changed this issue title to reflect further action better. Improving logging in that particular case can help when similar things are happening, so we will do that. I believe that logging JSON errors won't be enough to understand what's happening, and it will be better also to log the result of readProcess function.

Meanwhile, if you have troubles downloading licenses, you can use None license (which is AllRightsReserved), it works in offline mode and doesn't download anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants