rbenv / ruby-build

A tool to download, compile, and install Ruby on Unix-like systems.
https://rbenv.org/man/ruby-build.1
MIT License
3.89k stars 784 forks source link

"bad array subscript" error #2455

Open sanjioh opened 1 week ago

sanjioh commented 1 week ago

Steps to reproduce the behavior

rbenv install 2.7.8

Expected vs. actual behavior

I get the error /usr/local/bin/ruby-build: line 1158: versions: bad array subscript, right after issuing the command, which I suppose should not happen. The error is not blocking (build completes successfully).

Logs

$ ruby-build --version
ruby-build 20241017

This happens on an Intel Mac with macOS 14.7, ruby-build installed from Homebrew.

mislav commented 1 week ago

Thank you for reporting. This is strange, and I'm glad the error is at least non-fatal.

If you paste the following code into a bash shell, what does it output? (You could paste it into zsh too; it will likely work.)

  brew list 2>/dev/null | grep '^openssl@' | while read -r formula; do
    prefix="$(brew --prefix "$formula" 2>/dev/null || true)"
    [ -n "$prefix" ] || continue
    version="$("$prefix"/bin/openssl version 2>/dev/null | sed -n 's/OpenSSL \([0-9][0-9.]*\).*/\1/p')"
    [ -z "$version" ] || printf '%s %s %s\n' "$formula" "$version" "$prefix"
  done
sanjioh commented 1 week ago

Hi, thanks for replying.

The output is:

openssl@3 3.3.2 /usr/local/opt/openssl@3

mislav commented 4 days ago

Thanks for checking. That looks okay, so I actually don't know what triggers the "bad array subscript" error. However, I do think that ruby-build is trying to access an array at index -1 somehow, so I could add a guard around that, even if I don't understand how that index happened to be.

https://github.com/rbenv/ruby-build/blob/572dd651de863c90ee3f56ae2dd7dc3d7d7dd54b/bin/ruby-build#L1155-L1158