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

Job failure when testing connection to remote #157

Open
amitds1997 opened this issue Jul 12, 2024 · 3 comments
Open

Job failure when testing connection to remote #157

amitds1997 opened this issue Jul 12, 2024 · 3 comments

Comments

@amitds1997
Copy link
Owner

I came across the above problem while trying to debug my main machine which fails on the echo 'Hello' check with the following output:

DEBUG Wed 10 Jul 2024 13:19:24 BST /nix/store/8qvna5qxr8yil5l53lchi9db9r7frfb7-vim-pack-dir/pack/myNeovimPackages/start/remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:866: [ssh][ubuntu-container] Starting remote neovim launch
DEBUG Wed 10 Jul 2024 13:19:24 BST /nix/store/8qvna5qxr8yil5l53lchi9db9r7frfb7-vim-pack-dir/pack/myNeovimPackages/start/remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:141: Did not find any existing configuration. Creating one now..
DEBUG Wed 10 Jul 2024 13:19:24 BST /nix/store/8qvna5qxr8yil5l53lchi9db9r7frfb7-vim-pack-dir/pack/myNeovimPackages/start/remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:995: ["ssh"]["ubuntu-container"] Running "echo 'Hello'"
DEBUG Wed 10 Jul 2024 13:19:25 BST /nix/store/8qvna5qxr8yil5l53lchi9db9r7frfb7-vim-pack-dir/pack/myNeovimPackages/start/remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:1015: ["ssh"]["ubuntu-container"] Running "echo 'Hello'" completed
ERROR Wed 10 Jul 2024 13:19:25 BST /nix/store/8qvna5qxr8yil5l53lchi9db9r7frfb7-vim-pack-dir/pack/myNeovimPackages/start/remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:973: 'Testing remote connection' failed.
stack traceback:
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:974: in function '_handle_job_completion'
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:1017: in function 'run_command'
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:142: in function '_setup_workspace_variables'
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:872: in function '_launch_neovim'
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:883: in function <.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:882>
	[C]: in function 'xpcall'
	.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:759: in function <.../remote-nvim.nvim/lua/remote-nvim/providers/provider.lua:758> 

FAILED JOB OUTPUT (SO FAR)
bash: -c: line 1: unexpected EOF while looking for matching `''
bash: -c: line 2: syntax error: unexpected end of file

Which uses OpenSSH_9.8, but since I am going from a NixOS machine to a docker container, there are more than a few moving parts to investigate along the lines of #150 before I feel comfortable opening a new issue. If you have any ideas what might be causing this please let me know!

Originally posted by @TakodaS in #147 (comment)

@amitds1997
Copy link
Owner Author

Could you please provide a minimal reproducible example for this?

@TakodaS
Copy link

TakodaS commented Jul 12, 2024

As mentioned in #155 the issue is the result of a call to vim.fn.shellescape. Logging the raw command returns "echo 'Hello'" -> "ssh remote 'echo '\\''Hello'\\'''". Running print(vim.fn.shellescape("echo 'Hello'") returns 'echo '\''Hello'\'''

Running the following commands directly from terminal give the following outputs:

ssh remote 'echo '\\''Hello'\\'' -> \\Hello\

ssh remote 'echo '\''Hello'\''' -> [same error as reported]

talk2drys added a commit to talk2drys/remote-nvim.nvim that referenced this issue Nov 15, 2024
Fixed an issue with `run_command("echo 'Hello'")` where wrapping commands
in args in single quotes caused invalid parsing in POSIX-compliant shells.
In these shells, single quotes enclose literal text, making escape sequences
like `\'` invalid. For more details, refer to the GNU Bash manual:
https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html.

For example, calling `run_command("echo 'Hello'")` would be incorrectly
escaped by `vim.fn.shellescape` as `echo '\''Hello'\''`, leading to
invalid parsing. The fix replaces the outer double quotes with single
quotes where necessary and command arg with double qoute, ensuring proper
escaping and compatibility across different shell environments.

Signed-off-by: Daniel Temiagin <[email protected]>
@talk2drys
Copy link

The issue arises when calling run_command("echo 'Hello'"). The problem is in how shellescape escapes the command output. Specifically, it incorrectly wraps the argument in single quotes escaping the single qoute, causing issues when executing the command.

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

No branches or pull requests

3 participants