Sam
Sam

Reputation: 1132

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

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

debug test image

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

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

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?

Upvotes: 9

Views: 3578

Answers (4)

Daniel
Daniel

Reputation: 311

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.

See following example of .vscode/settings.json:

  1. Non-string value (here: boolean, but it applies to numbers too) which causes the reported error:
{
    "go.testEnvFile": "${workspaceFolder}/.env",
    "go.testEnvVars": {
        "SOME_TEST_PROPERTY": true
    }
}
  1. String value which works like a charm:
{
    "go.testEnvFile": "${workspaceFolder}/.env",
    "go.testEnvVars": {
        "SOME_TEST_PROPERTY": "true"
    }
}

Upvotes: 1

Justin Kloos
Justin Kloos

Reputation: 21

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" [...]},
  [...]
},

Upvotes: 2

Alexey Abramychev
Alexey Abramychev

Reputation: 1

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

Upvotes: 0

sbrichards
sbrichards

Reputation: 2210

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.

Upvotes: 0

Related Questions