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

Automatic Ruby environment activation with none failed: Unexpected token 'y' "your 13107"... is not valid JSON #2370

Closed
jared-thoughtbot opened this issue Jul 26, 2024 · 7 comments · Fixed by #2552
Assignees
Labels
bug Something isn't working

Comments

@jared-thoughtbot
Copy link

Description

Error

Automatic Ruby environment activation with none failed:
Unexpected token 'y' "your 13107"... is not valid JSON

image

My environment

  • VS Code v1.91.1
  • Ruby LSP VS Code extension v0.7.14
  • OS: Windows 11 23H2
  • Using WSL2 (Ubuntu 20.04.5 LTS)
  • Fish shell v3.7.1
  • Ruby 3.3.0
  • Ruby version manager: RVM v1.29.12

Reproduction steps

  1. My environment (as above)
  2. Launch VSCode (with Ruby LSP extension) via code . from WSL console
  3. Wait for extension to try and load

Error message

Automatic Ruby environment activation with none failed:
Unexpected token 'y' "your 13107"... is not valid JSON

Output tab (Ruby LSP)

2024-07-25 16:09:50.364 [info] (albaik-web) Checking if chruby is available on the path with command: /usr/bin/fish -i -c 'chruby --version'
2024-07-25 16:09:51.368 [info] (albaik-web) Checking if rbenv is available on the path with command: /usr/bin/fish -i -c 'rbenv --version'
2024-07-25 16:09:52.372 [info] (albaik-web) Checking if rvm is available on the path with command: /usr/bin/fish -i -c 'rvm --version'
2024-07-25 16:09:53.377 [info] (albaik-web) Checking if asdf is available on the path with command: /usr/bin/fish -i -c 'asdf --version'
2024-07-25 16:09:54.390 [info] (albaik-web) Discovered version manager none
2024-07-25 16:09:54.390 [info] (albaik-web) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/jaredt/projects/albaik-web using shell: /usr/bin/fish
2024-07-25 16:10:00.645 [error] (albaik-web) Tried parsing invalid JSON environment: your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
your 131072x1 screen size is bogus. expect trouble
{"env":{"COLORTERM":"truecolor","ANDROID_HOME":"/home/jaredt/Android/Sdk","BROWSER":"wslview","TERM":"xterm-256color","PATH":"/home/jaredt/.rvm/gems/ruby-3.3.0/bin:/home/jaredt/.rvm/gems/ruby-3.3.0@global/bin:/home/jaredt/.rvm/rubies/ruby-3.3.0/bin:/home/jaredt/.rvm/bin:/home/jaredt/.pyenv/shims:/home/jaredt/.pyenv/bin:/home/linuxbrew/.linuxbrew/opt/openssl@3/bin:/home/jaredt/.yarn/bin:/home/jaredt/bin:/home/jaredt/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729/bin/remote-cli:/home/jaredt/.asdf/shims:/home/jaredt/.asdf/bin:/bin:/home/jaredt/.local/share/nvm/v16.14.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/dotnet:/mnt/c/Program Files x86/Yarn/bin:/mnt/c/Program Files x86/Tailscale IPN:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/OpenSSL-Win64/bin:/mnt/c/Program Files/Mullvad VPN/resources:/mnt/c/Program Files x86/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/PowerShell/7:/mnt/c/Users/jared/AppData/Local/Programs/Python/Python37-32/Scripts:/mnt/c/Users/jared/AppData/Local/Programs/Python/Python37-32:/mnt/c/Users/jared/AppData/Local/Microsoft/WindowsApps:/mnt/c/path:/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/jared/.dotnet/tools:/mnt/c/Users/jared/AppData/Roaming/npm:/mnt/c/Users/jared/AppData/Local/Yarn/bin:/mnt/c/Users/jared/AppData/Roaming/nvm:/mnt/c/Program Files/nodejs:/snap/bin","rvm_delete_flag":"0","PYENV_ROOT":"/home/jaredt/.pyenv","LANG":"C.UTF-8","rvm_tmp_path":"/home/jaredt/.rvm/tmp","GEM_HOME":"/home/jaredt/.rvm/gems/ruby-3.3.0","rvm_action":"reload","rvm_version":"1.29.12 latest","rvm_gemsets_path":"/home/jaredt/.rvm/gemsets","rvm_stored_umask":"0022","rvm_verbose_flag":"0","NAME":"Code","ELECTRON_RUN_AS_NODE":"1","VSCODE_IPC_HOOK_CLI":"/mnt/wslg/runtime-dir/vscode-ipc-5af6e075-4536-4434-af98-ee919d7381ea.sock","WSL_DISTRO_NAME":"Ubuntu","rvm_environments_path":"/home/jaredt/.rvm/environments","rvm_patches_path":"/home/jaredt/.rvm/patches","PWD":"/home/jaredt/projects/albaik-web","rvm_src_path":"/home/jaredt/.rvm/src","rvm_docs_path":"/home/jaredt/.rvm/docs","XDG_DATA_DIRS":"/usr/local/share:/usr/share:/var/lib/snapd/desktop","VSCODE_HANDLES_SIGPIPE":"true","rvm_hooks_path":"/home/jaredt/.rvm/hooks","SHLVL":"1","rvm_user_install_flag":"1","rvm_lib_path":"/home/jaredt/.rvm/lib","VSCODE_WSL_EXT_LOCATION":"/mnt/c/Users/jared/.vscode/extensions/ms-vscode-remote.remote-wsl-0.88.2","ASDF_DIR":"/home/jaredt/.asdf","PULSE_SERVER":"unix:/mnt/wslg/PulseServer","rvm_archives_path":"/home/jaredt/.rvm/archives","WT_PROFILE_ID":"{2c4de342-38b7-51cf-b940-2309a097f518}","rvm_repos_path":"/home/jaredt/.rvm/repos","PYENV_SHELL":"fish","XDG_RUNTIME_DIR":"/mnt/wslg/runtime-dir","VSCODE_L10N_BUNDLE_LOCATION":"","rvm_path":"/home/jaredt/.rvm","rvm_bin_path":"/home/jaredt/.rvm/bin","rvm_examples_path":"/home/jaredt/.rvm/examples","WAYLAND_DISPLAY":"wayland-0","HOME":"/home/jaredt","rvm_prefix":"/home/jaredt","rvm_help_path":"/home/jaredt/.rvm/help","LOGNAME":"jaredt","rvm_scripts_path":"/home/jaredt/.rvm/scripts","rvm_pretty_print_flag":"auto","VSCODE_CWD":"/mnt/c/Users/jared/AppData/Local/Programs/Microsoft VS Code","SHELL":"/usr/bin/fish","rvm_loaded_flag":"1","rvm_token":"reload","rvm_user_path":"/home/jaredt/.rvm/user","DISPLAY":":0","WSL_INTEROP":"/run/WSL/27414_interop","rvm_parse_break":"0","rvm_man_path":"/home/jaredt/.rvm/share/man","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","rvm_debug_flag":"0","rvm_usr_path":"/home/jaredt/.rvm/usr","rvm_log_path":"/home/jaredt/.rvm/log","rvm_rubies_path":"/home/jaredt/.rvm/rubies","WT_SESSION":"f5a6c79f-7043-4744-a9d7-ee9ef745bfca","rvm_wrappers_path":"/home/jaredt/.rvm/wrappers","nvm_current_version":"v16.14.0","HOSTTYPE":"x86_64","VSCODE_NLS_CONFIG":"{\"locale\":\"en\",\"osLocale\":\"en\",\"availableLanguages\":{}}","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","USER":"jaredt","WSLENV":"ELECTRON_RUN_AS_NODE/w:WT_SESSION:WT_PROFILE_ID:","WSL2_GUI_APPS_ENABLED":"1","rvm_ruby_string":"ruby-3.3.0","GEM_PATH":"/home/jaredt/.rvm/gems/ruby-3.3.0:/home/jaredt/.rvm/gems/ruby-3.3.0@global"},"yjit":true,"version":"3.3.0"}

Running commands directly in terminal (Fish shell)

$ rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

$ /usr/bin/fish -i -c 'rvm --version'
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

$ which ruby
/home/jaredt/.rvm/rubies/ruby-3.3.0/bin/ruby

$ ruby-lsp
Ruby LSP> Skipping custom bundle setup since /home/jaredt/projects/albaik-web/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: ((bundle check && bundle update ruby-lsp debug ruby-lsp-rails) || bundle install) 1>&2
The Gemfile's dependencies are satisfied
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Resolving dependencies...
Fetching sorbet-runtime 0.5.11495 (was 0.5.11493)
Installing sorbet-runtime 0.5.11495 (was 0.5.11493)
Bundler attempted to update ruby-lsp but its version stayed the same
Bundler attempted to update debug but its version stayed the same
Bundler attempted to update ruby-lsp-rails but its version stayed the same
Bundle updated!

Notes

  • It detects I'm using Fish ✅
  • It doesn't find rvm but running the same command from the terminal works fine
  • your 131072x1 screen size is bogus. expect trouble - I have no idea about this but it doesn't sound good 🙃
  • I'm very open to this being a me problem but I'd love if someone could take a look :)
@jared-thoughtbot jared-thoughtbot added the bug Something isn't working label Jul 26, 2024
@motebaya
Copy link

Maybe this is similar to a problem I recently experienced (#2369 ). The cause was the default terminal in VSCode not being compatible.

Screenshot 2024-07-27 150347

In fish shell, you can try changing the terminal size with the mouse or adjust the shell variables in the ~/.config/fish/config.fish file with values like

set -x COLUMNS 114
set -x LINES 48

or whatever size you prefer as long as it's more than 1.
based: https://fishshell.com/docs/current/cmds/set.html

another quick solution is to change the default terminal in VSCode; that might fix the issue.

@jared-thoughtbot
Copy link
Author

@motebaya amazing, thank you! Both options worked but I settled on hardcoding the columns and lines in config.fish.

Weirdly it still doesn't detect my version manager but it is working 🤷

2024-07-27 13:11:22.742 [info] (albaik-web) Checking if chruby is available on the path with command: /usr/bin/fish -i -c 'chruby --version'
2024-07-27 13:11:23.748 [info] (albaik-web) Checking if rbenv is available on the path with command: /usr/bin/fish -i -c 'rbenv --version'
2024-07-27 13:11:24.752 [info] (albaik-web) Checking if rvm is available on the path with command: /usr/bin/fish -i -c 'rvm --version'
2024-07-27 13:11:25.766 [info] (albaik-web) Checking if asdf is available on the path with command: /usr/bin/fish -i -c 'asdf --version'
2024-07-27 13:11:26.776 [info] (albaik-web) Discovered version manager none
2024-07-27 13:11:26.777 [info] (albaik-web) Running command: `ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/jaredt/projects/albaik-web using shell: /bin/fish
2024-07-27 13:11:38.653 [info] (albaik-web) Ruby LSP> Skipping custom bundle setup since /home/jaredt/projects/albaik-web/.ruby-lsp/Gemfile.lock already exists and is up to date
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2
The Gemfile's dependencies are satisfied

2024-07-27 13:11:41.637 [info] (albaik-web) Initializing Ruby LSP v0.17.9...

2024-07-27 13:11:41.706 [info] (albaik-web) Finished initializing Ruby LSP!

2024-07-27 13:11:41.754 [info] (albaik-web) [Standard Ruby] Activating Standard Ruby LSP addon v1.39.1

2024-07-27 13:11:42.647 [info] (albaik-web) [Standard Ruby] Initialized Standard Ruby LSP addon 1.39.1

2024-07-27 13:11:42.647 [info] (albaik-web) Activating Ruby LSP Rails addon v0.3.11

2024-07-27 13:11:42.692 [info] (albaik-web) Ruby LSP Rails booting server

2024-07-27 13:11:49.531 [info] (albaik-web) Finished booting Ruby LSP Rails server

@motebaya
Copy link

motebaya commented Jul 27, 2024

@jared-thoughtbot Have you tried setting the version manager manually? i think in log, LSP checking version manager because you haven't set it up yet.

Here's what i did:

  1. in vscode, press CTRL + SHIFT + P, type version manager -> change version manager -> and select the version manager you have.
  2. create a .ruby_version file with the ruby version you're using in current directory project.
  3. adding the RUBY_VERSION variable to the ENV.

it might help.

@ur5us
Copy link

ur5us commented Aug 8, 2024

I have the same issue but only in 1 project:

Automatic Ruby environment activation with rvm failed: Unexpected token 'N', "No preset "... is not valid JSON

Using RVM to manage Ruby but also asdf to manage NodeJS. Bash is my shell. Annoyingly, it’s not consistent, i.e. the LSP works for gems and all other Ruby/Rails projects I work on except for one. Last week it worked without issues IIRC.

@jared-thoughtbot
Copy link
Author

@ur5us can you provide the content from the Output tab with Ruby LSP selected from the dropdown? Eg.

image

@ur5us
Copy link

ur5us commented Aug 8, 2024

@jared-thoughtbot I think I solved it. The problem was asdf complaining about NodeJS version as per .tool-versions not installed, though IMO that should not affect the Ruby LSP in the first place as I’m using RVM to manage my Ruby versions. For reference:

2024-08-08 16:42:45.145 [info] (app) Running command: `/home/ur5us/.rvm/bin/rvm-auto-ruby -W0 -rjson -e 'STDERR.print({ env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION }.to_json)'` in /home/ur5us/dev/redacted/app using shell: /usr/bin/bash
2024-08-08 16:42:47.377 [error] (app) Tried parsing invalid JSON environment: No preset version installed for command node
Please install a version by running one of the following:

asdf install nodejs 20.16.0

or add one of the following versions in your config file at /home/ur5us/dev/redacted/app/.tool-versions
nodejs 18.17.1
nodejs 20.13.0
nodejs 20.14.0
nodejs 20.15.0
nodejs 20.15.1
nodejs 22.0.0
{"env":{"SHELL":"/bin/bash","SESSION_MANAGER":"local/dragonfly:@/tmp/.ICE-unix/1538,unix/dragonfly:/tmp/.ICE-unix/1538","CSF_MDTVTexturesDirectory":"/usr/share/opencascade/resources/Textures","XDG_CONFIG_DIRS":"/run/xdg/:/etc/xdg/:/usr/share/xdg/","XDG_SESSION_PATH":"/org/freedesktop/DisplayManager/Session0","HISTCONTROL":"ignoredups","XDG_MENU_PREFIX":"gnome-","rvm_delete_flag":"0","__GL_MaxFramesAllowed":"1","rvm_prefix":"/home/ur5us","CSF_DrawPluginDefaults":"/usr/share/opencascade/resources/DrawResources","HISTSIZE":"1000","CSF_LANGUAGE":"us","SSH_AUTH_SOCK":"/run/user/1000/keyring/ssh","CSF_MIGRATION_TYPES":"/usr/share/opencascade/resources/StdResource/MigrationSheet.txt","ELECTRON_RUN_AS_NODE":"1","MY_RUBY_HOME":"/home/ur5us/.rvm/rubies/ruby-3.3.4","XMODIFIERS":"@im=ibus","DESKTOP_SESSION":"budgie-desktop","CSF_OCCTResourcePath":"/usr/share/opencascade/resources","NO_AT_BRIDGE":"1","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","CSF_STEPDefaults":"/usr/share/opencascade/resources/XSTEPResource","EMSCRIPTEN_ROOT":"/usr/share/emscripten/emsdk","EDITOR":"code-oss -w","GTK_MODULES":"gail:atk-bridge:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module:appmenu-gtk-module","RUBY_VERSION":"ruby-3.3.4","PWD":"/home/ur5us/dev/redacted/app","LOGNAME":"ur5us","XDG_SESSION_DESKTOP":"budgie-desktop","XDG_SESSION_TYPE":"x11","DRAWHOME":"/usr/share/opencascade/resources/DrawResources","BUNDLER_EDITOR":"code-oss","rvm_version":"1.29.12-next (master)","VSCODE_CODE_CACHE_PATH":"/home/ur5us/.config/Code/CachedData/b1c0a14de1414fcdaa400695b4db1c0799bc3124","XAUTHORITY":"/home/ur5us/.Xauthority","CSF_StandardLiteDefaults":"/usr/share/opencascade/resources/StdResource","XDG_GREETER_DATA_DIR":"/var/lib/lightdm-data/ur5us","MOTD_SHOWN":"pam","GDM_LANG":"en_NZ.UTF-8","BINARYEN_ROOT":"/usr","HOME":"/home/ur5us","LANG":"en_NZ.UTF-8","XDG_CURRENT_DESKTOP":"Budgie:GNOME","BINARYEN":"/usr","VSCODE_IPC_HOOK":"/run/user/1000/vscode-0b167dcd-1.92-main.sock","PROMPT_COMMAND":"history -a;","XDG_SEAT_PATH":"/org/freedesktop/DisplayManager/Seat0","VSCODE_L10N_BUNDLE_LOCATION":"","CSF_ShadersDirectory":"/usr/share/opencascade/resources/Shaders","CHROME_DESKTOP":"code-oss.desktop","CSF_EXCEPTION_PROMPT":"1","CSF_XmlOcafResource":"/usr/share/opencascade/resources/XmlOcafResource","rvm_bin_path":"/home/ur5us/.rvm/bin","CSF_SHMessage":"/usr/share/opencascade/resources/SHMessage","GEM_PATH":"/home/ur5us/.rvm/gems/ruby-3.3.4:/home/ur5us/.rvm/gems/ruby-3.3.4@global","GEM_HOME":"/home/ur5us/.rvm/gems/ruby-3.3.4","XDG_SESSION_CLASS":"user","ASDF_DIR":"/home/ur5us/.asdf","USER":"ur5us","CSF_StandardDefaults":"/usr/share/opencascade/resources/StdResource","CSF_IGESDefaults":"/usr/share/opencascade/resources/XSTEPResource","VISUAL":"/usr/bin/nano","DISPLAY":":0","CSF_XCAFDefaults":"/usr/share/opencascade/resources/StdResource","VSCODE_PID":"631451","SHLVL":"0","INPUTRC":"/etc/inputrc","QT_IM_MODULE":"ibus","NO_GAIL":"1","VSCODE_CWD":"/home/ur5us","CSF_PluginDefaults":"/usr/share/opencascade/resources/StdResource","CSF_TObjMessage":"/usr/share/opencascade/resources/TObj","rvm_ruby_string":"ruby-3.3.4","CASROOT":"/usr","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","XDG_RUNTIME_DIR":"/run/user/1000","CSF_XSMessage":"/usr/share/opencascade/resources/XSMessage","GTK3_MODULES":"xapp-gtk3-module","MMGT_CLEAR":"1","XDG_DATA_DIRS":"/home/ur5us/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop","GDK_BACKEND":"x11","PATH":"/home/ur5us/.rvm/gems/ruby-3.3.4/bin:/home/ur5us/.rvm/gems/ruby-3.3.4@global/bin:/home/ur5us/.rvm/rubies/ruby-3.3.4/bin:/home/ur5us/.rvm/bin:/home/ur5us/.asdf/shims:/home/ur5us/.asdf/bin:/home/ur5us/.local/bin:/home/ur5us/bin:/usr/sbin:/usr/bin:/usr/local/bin:/snap/bin:/usr/local/bin:/home/ur5us/.cargo/bin:/home/ur5us/.local/bin:/home/ur5us/bin::/home/ur5us/.dotnet","CSF_TObjDefaults":"/usr/share/opencascade/resources/StdResource","HISTIGNORE":"history:ls:cd:exit","GDMSESSION":"budgie-desktop","ORIGINAL_XDG_CURRENT_DESKTOP":"Budgie:GNOME","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1000/bus","VSCODE_NLS_CONFIG":"{\"userLocale\":\"en-us\",\"osLocale\":\"en-nz\",\"resolvedLanguage\":\"en\",\"defaultMessagesFile\":\"/usr/share/vscode/resources/app/out/nls.messages.json\",\"locale\":\"en\",\"availableLanguages\":{}}","MAIL":"/var/spool/mail/ur5us","IRBRC":"/home/ur5us/.rvm/rubies/ruby-3.3.4/.irbrc","DRAWDEFAULT":"/usr/share/opencascade/resources/DrawResources/DrawDefault","GIO_LAUNCHED_DESKTOP_FILE_PID":"631451","GIO_LAUNCHED_DESKTOP_FILE":"/usr/share/applications/code-oss.desktop","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","rvm_path":"/home/ur5us/.rvm"},"yjit":true,"version":"3.3.4"}

@vinistock
Copy link
Member

I believe #2552 should make this a bit more robust. Since we need to invoke the shell to integrate with version managers, we are susceptible to what gets printed by plugins or shell configs.

Hopefully, putting the JSON environment for the activation between separators will make this a bit more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants