Skip to content

Conversation

@sakakibara
Copy link
Contributor

This fixes #150 which happens when there's no version specified for gems in $HOME/.default-gems file.

@Stratus3D
Copy link
Member

Can you explain what this change does? I'm not sure I understand what it is doing.

@sakakibara
Copy link
Contributor Author

@Stratus3D
Sorry I should have explained a little more.

I'm experiencing #150 on bash 3.2.57 which is default version of bash installed on macOS Mojave. And that is the version I tested this pull request with.

When trying to find the culprit by trial and error I figured out the error won't happen when I have the gem version specified in $HOME/.default-gems.

I then tested without the gem version specified after I made the following modification to line 106 of bin/install.

    # if output=$($gem install "$gem_name" "${args[@]:-}" 2>&1); then
    if output=$($gem install "$gem_name" 2>&1); then

Then it caused no error.

Using the syntax "${args[@]:-}" array expands into empty string.
Where as "${args[@]+"args[@]}"}" expands into nothing, as right hand side of + won't be expanded if args array is unset.

You can see the difference in two using the following script.

#!/usr/bin/env bash

echo_size() {
  echo "size: $#"
  echo "content: '${args[*]}'"
}

main() {
  local args=()
  local echoed_size

  echoed_size="$(echo_size "${args[@]:-}")"
  echo "${echoed_size}"

  echoed_size="$(echo_size "${args[@]+"${args[@]}"}")"
  echo "${echoed_size}"
}

main

The output is

size: 1
content: ''
size: 0
content: ''

@Stratus3D
Copy link
Member

Excellent! Thanks for the detailed explanation and the script!

I also reproduced this by running:

$ gem install bundler '' # fails with the marshal data too short error
$ gem install bundler # succeeds

@Stratus3D Stratus3D merged commit 5205df8 into asdf-vm:master Apr 28, 2020
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

Successfully merging this pull request may close these issues.

Marshal data too short error when installing default gems

2 participants