通过 VS Code 在 minikube 中远程调试 pod 出现错误,并出现来自 remoteProcessPickerScript 的解析错误

问题描述 投票:0回答:2

突然间,我在使用 launch.json 和安装在 .net core 项目的 docker 容器中的远程调试器通过 VS Code 进行远程调试时遇到问题..

错误消息清楚地说明了问题是什么,对我来说,与指向的错误相比,查看该文件没有任何意义。 (顺便说一句,正在使用的本地文件看起来与此链接中文件的主分支完全相同:remoteProcessPickerScript

这是我在尝试通过 dotnet 环境将 VS Code 的远程调试功能附加到 pod 时遇到的错误:

kubectl exec -i pod-name -- /bin/sh -c "sh -s" < "c:\...\.vscode\extensions\ms-dotnettools.csharp-2.10.28-win32-x64\scripts\remoteProcessPickerScript"
stderr: sh: 30: Syntax error: "}" unexpected (expecting "then")
command terminated with exit code 2
c# kubernetes visual-studio-code minikube remote-debugging
2个回答
0
投票

我遇到了同样的问题,就我而言,它与remoteProcessPickerScript 文件的行结尾有关。我通过在 VS Code 中打开它并将行结尾从 CRLF 更改为 LF 并重新运行来解决这个问题。

但是,我不确定此问题的根本原因,因为 master 分支上的文件具有正确的行结尾。


0
投票

确保本地

remoteProcessPickerScript
目录中的
.vscode
与 GitHub 存储库 master 分支中的完全匹配。任何偏差都可能导致语法错误。

# Compare local script with the remote one
diff "c:\...\.vscode\extensions\ms-dotnettools.csharp-2.10.28-win32-x64\scripts\remoteProcessPickerScript" "path/to/downloaded/script/from/github"

该脚本可能是为特定 shell(如 bash)编写的,但它由另一个 shell(如 sh)解释。确保脚本的 shebang 行(如果有)与容器中使用的 shell 匹配。

如果您使用的是 Windows 计算机,脚本中的行结尾可能是

CRLF
,而不是 Unix 风格的
LF
。这可能会在 Unix 环境中导致问题。

# Convert CRLF to LF
dos2unix "c:\...\.vscode\extensions\ms-dotnettools.csharp-2.10.28-win32-x64\scripts\remoteProcessPickerScript"

此外,如果脚本中有特殊字符,它们在传递时可能需要以不同的方式转义

kubectl exec

为了进行测试,请尝试直接在容器的 shell 中运行脚本

kubectl exec -i pod-name -- /bin/bash -c "cat > script.sh" < "c:\...\.vscode\extensions\ms-dotnettools.csharp-2.10.28-win32-x64\scripts\remoteProcessPickerScript"
kubectl exec -it pod-name -- /bin/bash -c "./script.sh"
© www.soinside.com 2019 - 2024. All rights reserved.