无法在VSCode(golang)中使“debug test”正常工作。

huangapple go评论98阅读模式
英文:

Cannot get "debug test" to work in VSCode (golang)

问题

调试测试以前是完美运行的,但最近某个时刻发生了一些变化,现在不再工作(可能是Go版本升级了?)。

当我点击“debug test”时,出现了以下错误信息:

无法在VSCode(golang)中使“debug test”正常工作。

错误信息为:Failed to launch: invalid debug configuration - cannot unmarshal bool into "env" of type string

我的 launch.json 看起来没问题(再次强调,以前是完美运行的):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch test function",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "program": "${workspaceFolder}",
            "env": {
                "LOG_LEVEL": "debug",
                "LOG_SQL": "false",
                "DATABASE_URL": "postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable",
            },
            "args": ["-v"]
        },
    ]
}

可能出了什么问题?

英文:

Debugging tests to work perfectly but at some point recently something changed, and now it doesn't (perhaps a go version upgrade?).

无法在VSCode(golang)中使“debug test”正常工作。

When I click "debug test" this error message pops up:

无法在VSCode(golang)中使“debug test”正常工作。

The error is: Failed to launch: invalid debug configuration - cannot unmarshal bool into "env" of type string

My launch.json seems fine (again, this used to work perfectly):

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch test function",
        "type": "go",
        "request": "launch",
        "mode": "test",
        "program": "${workspaceFolder}",
        "env": {
            "LOG_LEVEL": "debug",
            "LOG_SQL": "false",
            "DATABASE_URL": "postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable",
        },
        "args": ["-v"]
    },
]

}

What could be wrong?

答案1

得分: 2

我遇到了同样的问题。我在我的全局配置中设置了CGO_ENABLED=0。然而,有些东西正在覆盖这个设置,现在期望的是一个字符串。在你的launch.json文件中尝试像这样设置:

{
  [...]
  "env": {[...] "CGO_ENABLED": "0" [...]},
  [...]
},
英文:

I had the same issue. I have CGO_ENABLED=0 in my global config. However, something is overriding and now expecting a String instead. Try something like this in your launch.json:

{
  [...]
  "env": {[...] "CGO_ENABLED": "0" [...]},
  [...]
},

答案2

得分: 0

只是猜测,是因为"LOG_SQL"是"false"而不是false(字符串 vs 布尔值),它试图将"false"解析为布尔值。

英文:

Just a guess, but is it because “LOG_SQL” is “false” instead of false (string vs bool), and it’s trying to parse “false” to bool.

答案3

得分: 0

遇到了同样的问题。通过以下步骤解决:

  1. 在 launch.json 中添加一行代码:"envFile": "${workspaceFolder}/.vscode/server.env"
  2. 在 ${workspaceFolder}/.vscode/ 目录下创建 server.env 文件,并添加以下内容:
    LOG_LEVEL=debug
    LOG_SQL=false
    DATABASE_URL=...
  3. 从 launch.json 中删除 env 部分。
英文:
Have the same issue. Did solve by 
1. added line  "envFile": "${workspaceFolder}/.vscode/server.env" to launch.json
2. added file server.env into ${workspaceFolder}/.vscode/ with following content:
    LOG_LEVEL=debug 
    LOG_SQL=false
    DATABASE_URL=...
3. And removed env section from launch.json

答案4

得分: 0

我遇到了同样的问题,结果发现是因为我的 settings.json 中有一个键/值对,其中值是一个数字。我将其转换为字符串后,问题就解决了。我原以为在调试时只有 launch.json 被使用,但看来并非如此。

英文:

I had the same issue and it turns out it was because of a key/value pair in my settings.json where the value was a number. I turned it into a string and it worked fine. I though VS code only used the launch.json when debugging, but I guess not.

huangapple
  • 本文由 发表于 2022年2月23日 23:52:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/71240154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定