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

errors in the installation command #423

Closed
bsun0802 opened this issue Jun 5, 2020 · 12 comments
Closed

errors in the installation command #423

bsun0802 opened this issue Jun 5, 2020 · 12 comments

Comments

@bsun0802
Copy link

bsun0802 commented Jun 5, 2020

The following error appears when installing rustlings with provided script curl -L https://git.io/rustlings | bash the rustlings executable is installed successfully tho. Please give it a check.

===============================
Traceback (most recent call last):
File "", line 1, in
File "/opt/anaconda3/lib/python3.7/json/init.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/opt/anaconda3/lib/python3.7/json/init.py", line 348, in loads
return _default_decoder.decode(s)
File "/opt/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Checking out version ...
error: pathspec 'tags/' did not match any file(s) known to git

@AbdouSeck
Copy link
Contributor

@bsun0802 without more details (like your OS info, your curl version, etc.), it is going to be hard for us to determine what the issue may be.

What I can guess is that the curl -s call inside the install script at https://git.io/rustlings is failing, so the python line is receiving an empty string for JSON data. Therefore, python is failing to decode said empty string into a python object.

Questions:

  • What's your OS info: uname -a
  • What's your curl version: curl --version
  • What do you see when you run curl https://api.github.com/repos/rust-lang/rustlings/releases/latest

Thank you,

Abdou

AbdouSeck added a commit to AbdouSeck/rustlings that referenced this issue Jun 5, 2020
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
@bsun0802
Copy link
Author

bsun0802 commented Jun 6, 2020

Thanks,

  1. curl version 7.69.1.

  2. The uname -a output is as following.
    Darwin bsunmbp2 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

  3. the curl https://api.github.com/repos/rust-lang/rustlings/releases/latest command returns a valid json I think.

{
  "url": "https://api.github.com/repos/rust-lang/rustlings/releases/25420239",
  "assets_url": "https://api.github.com/repos/rust-lang/rustlings/releases/25420239/assets",
  "upload_url": "https://uploads.github.com/repos/rust-lang/rustlings/releases/25420239/assets{?name,label}",
  "html_url": "https://github.com/rust-lang/rustlings/releases/tag/3.0.0",
  "id": 25420239,
  "node_id": "MDc6UmVsZWFzZTI1NDIwMjM5",
  "tag_name": "3.0.0",
  "target_commitish": "master",
  "name": "Rustlings 3.0.0",
  "draft": false,
  "author": {
    "login": "fmoko",
    "id": 6445316,
    "node_id": "MDQ6VXNlcjY0NDUzMTY=",
    "avatar_url": "https://avatars2.githubusercontent.com/u/6445316?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/fmoko",
    "html_url": "https://github.com/fmoko",
    "followers_url": "https://api.github.com/users/fmoko/followers",
    "following_url": "https://api.github.com/users/fmoko/following{/other_user}",
    "gists_url": "https://api.github.com/users/fmoko/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/fmoko/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/fmoko/subscriptions",
    "organizations_url": "https://api.github.com/users/fmoko/orgs",
    "repos_url": "https://api.github.com/users/fmoko/repos",
    "events_url": "https://api.github.com/users/fmoko/events{/privacy}",
    "received_events_url": "https://api.github.com/users/fmoko/received_events",
    "type": "User",
    "site_admin": false
  },
  "prerelease": false,
  "created_at": "2020-04-11T22:01:08Z",
  "published_at": "2020-04-11T22:04:24Z",
  "assets": [

  ],
  "tarball_url": "https://api.github.com/repos/rust-lang/rustlings/tarball/3.0.0",
  "zipball_url": "https://api.github.com/repos/rust-lang/rustlings/zipball/3.0.0",
  "body": "See the [changelog](https://github.com/fmoko/rustlings/blob/master/CHANGELOG.md#300-2020-04-11) for what's changed.\r\n\r\nAs for what makes this a breaking release, in #278 we decided to make the `compile` exercise mode log its output to stdout. Since this changes existing user behaviour in a (broadly) backwards-incompatible way, we decided to make this a major release.\r\n\r\nThe good thing is that you don't need to do anything to upgrade! 🎉 \r\n\r\nTo upgrade:\r\n\r\n```sh\r\ngit fetch\r\ngit checkout tags/3.0.0\r\n```"
}

@alexxroche
Copy link
Contributor

Your copy of curl seems to be functioning as required, (and expected.) It looks like your python3 install is having problems parsing the json. You can verify with:

curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | $(command -v python3) -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);"

I'm thinking of patching the install script to default to jq rather than python. If you have brew installed, could you see if the following gives you the version number:

command -v jq||brew install jq;
curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | jq -r '.tag_name'

alexxroche added a commit to alexxroche/rustlings that referenced this issue Jun 6, 2020
rust-lang#423 (comment) was having problems installing. (I think their python3 install was having a problem parsing json?) Having an install fail just because it was unable to locate the version number seems like "my kingdom for a horseshoe nail" now that the version is relatively stable. (Its good to have a single point of truth, but) we could have an emergency version number of "3.0.0" in this file rather than have the install fail because rust and rustlings does not depend on python for to function.

Having this rustlings install depend on bash that depends on python seems like "extra steps" that could be avoided. The pure shell version also works with some other shells such as dash.
@AbdouSeck
Copy link
Contributor

Hi @alexxroche

While I agree that jq is a very good tool for handling JSON data on the terminal, I think using it in the installation script solves a problem by creating another eventual problem: adding a new dependency to the list of things needed before installing the binary.

I am not saying that having python as a dependency is the safest thing to do, but it is definitely safer (in terms of availability and function) than relying on jq. I say this because most (if not all) unix machines are shipped with some version of python on them, while no unix system, as far as I am aware, is shipped with jq as part of its SHELL utilities. I could be wrong about this one, though.

On top of that, when you add jq to the dependency list, you risk having to provide a safe installation procedure for jq and its dependencies.

Ultimately, the safest thing to do (in my opinion) when dealing with this installation script may be to fall back on the git tags that already come with the repository, or even use the master branch.
Ideally, if no valid tag can be parsed from the curl invocation, we could use git tag --list or simply ls .git/refs/tags to fetch the latest tag name.

If you look at my proposed changes in the linked pull request, you will see that the above mentioned attempts are being made to fetch a tag to install.

In summary, I am not saying that any one tool is better than the other. What I am trying to avoid is ultimately having to deal with more issues that will arise from adding new dependencies. I am definitely happy to be proven wrong in the name of ease and efficiency of use.

Thank you,

Abdou

@AbdouSeck
Copy link
Contributor

@bsun0802 are you able to see a tag name when you run the following directly from your terminal:

curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python3 -c "import json, sys; obj = json.load(sys.stdin); print(obj['tag_name'])"

?

Thank you,

Abdou

@alexxroche
Copy link
Contributor

I agree that adding dependencies is unhelpful. I have started to create a version of the install.sh that can bypass the python dependency entirely. (Is there any advantage to having the python dependency?) We can have jq as a more efficient optional for those that have jq installed, with the native shell script as the fallback option.

Installing jq on OSX can be done with brew install jq and on apt based linux with sudo apt-get install -y jq. (Both of which can be added to the install script.) I don't know how other operating systems can benefit from jq, but they can take the slower and less efficient native shell option.

@AbdouSeck
Copy link
Contributor

@alexxroche Let me begin by saying that I am for any installation that bypasses as many dependencies as possible. So, when you're done with the one you're working on, I will be the first to stick my sign of approval (if that means anything really) on it. My reservation was (and still is) that replacing one dependency with another may not solve the problem this issue is raising, and could eventually bring about other issues.
With that said, I will be excitedly on the lookout for your changes and will test them as soon as possible.

Thank you!

Abdou

@bsun0802
Copy link
Author

bsun0802 commented Jun 6, 2020

@AbdouSeck
Hi, running the command curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python3 -c "import json, sys; obj = json.load(sys.stdin); print(obj['tag_name'])"
print out 3.0.0 on my STDOUT.

@alexxroche
Copy link
Contributor

Thank you @bsun0802 (Looks like my guess was wrong about python being the problem.)
The install script locates python using
command -v python3||command -v python||command -v python2
so if that works it might have been a temporary network problem preventing curl from downloading, or a local curl config, (such as ls -la ~/.curlrc ) or a glitch with the github api rate limiter that let you download the install script, but then prevented the install script from downloading the file with the version number.
I've tried to recreate the problem with

  • curl 7.64.0 (after mv ~/.curlrc ~/.arch_curlrc )
  • python 3.7.3
  • GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

but have been unable to recreate this issue, (though I don't currently have a copy of OSX to check that ls -la $(which -a bash) isn't linked to some other shell.)

We could have install.sh check the exit code of curl to verify that it succeeded, (or ask to retry).

@bsun0802
Copy link
Author

bsun0802 commented Jun 7, 2020

Hi @alexxroche ,

Great thanks! I see, the network problem might be the issues. I'm from China so there definitely gonna be network (GFW) problems. I'll try to figure them out, I might need to perform some steps manually.

Thanks for all of you guys time and helps!!

@bsun0802 bsun0802 closed this as completed Jun 7, 2020
@shadows-withal
Copy link
Member

@bsun0802 Ah right, GitHub takes a long time to reach from China, so there may be timeouts. I'll see that we upload future Rustlings releases to some sort of edge servers so that they can be reached from most places in the world without erroring. Sorry about this!

@alexxroche
Copy link
Contributor

Or have the install script try to download a few times, (until timeout) and give a clear "Network Error" message if it is unable to download. (Its a shell script, so we can leverage [ $? -gt 0 ] && echo "Network Error"; )

I think the poor User eXperience was due to the python panic message when it tried to parse an empty file. I've written a version of the install that removes the python dependency and, (hopefully) will give clearer error messages if there is a network problem. (I can create a pull request if needed, but I wasn't sure if removing a dependency, (and adding the option to leverage jq) would be progress in the optimal direction for this project.)

MendelMonteiro pushed a commit to MendelMonteiro/rustlings that referenced this issue Jun 28, 2020
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
dlemel8 pushed a commit to dlemel8/rustlings that referenced this issue Aug 2, 2020
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
ppp3 pushed a commit to ppp3/rustlings that referenced this issue May 23, 2022
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
dmoore04 pushed a commit to dmoore04/rustlings that referenced this issue Sep 11, 2022
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants