Ingo Bürk
Ingo Bürk

Reputation: 20043

How to debug a Go function returning multiple values in IntelliJ?

Suppose we are debugging some Go code, and somewhere in an external dependency we encounter this line:

return json.Marshal(foo)

We want to set a breakpoint and use IntelliJ's "Evaluate Expression" to inspect the JSON being produced. However, this doesn't work:

So how can I use "Evaluate Expression" to achieve my goal of just printing the produced JSON string when I'm not able to change the underlying source code?

Upvotes: 0

Views: 449

Answers (1)

Pizza lord
Pizza lord

Reputation: 763

you can print the returned bytes as a string

bytes, err := json.Marshal(foo)
// check error here
fmt.Println(string(bytes))

update based on comments

You can't change the byte slice in the debugger to a string without changing the source code.

Upvotes: 3

Related Questions