0

How can I track down a function return mismatch in Golang? In two different build environments I am seeing a difference. Both cases should be Visual Studio Code remote to a Linux box, using Go 1.12 in module mode. The broken case is where I am driving the build using the Golang:1.12 Docker image. Below is simplified from where I'm seeing the problem.

So for this sample, derived from https://github.com/satori/go.uuid:

package main

import (
    "fmt"

    uuid "github.com/satori/go.uuid"
)

func main() {
    // or error handling
    u2, err := uuid.NewV4()
    if err != nil {
        fmt.Printf("Something went wrong: %s", err)
        return
    }
    fmt.Printf("UUIDv4: %s\n", u2)
}

The unexpected build error is:

./main.go:11:5 assignment mismatch: 2 variables but uuid.NewV4() returns 1 values

In the environment where I encounter this problem, in Visual Studio Code when I hover with mouse over the call to uuid.NewV4() I see:

func uuid.NewV4() (uuid.UUID, error)

uuid.NewV4 on pkg.go.dev

NewV4 returns random generated UUID.

and hover over uuid shows:

package uuid ("github.com/satori/go.uuid")

uuid on pkg.go.dev

I may switch to a different uuid package to work around this -- but I want to understand better how to figure this out.

learning2learn
  • 405
  • 5
  • 11

1 Answers1

3

I guess problem is in different github.com/satori/go.uuid module versions. You can see, that NewV4 function signature was updated to NewV4() (uuid.UUID, error) in latest version v1.2.0. Before that it was func NewV4() UUID

Then resolve to a specific version as in this question:

How to point Go module dependency in go.mod to a latest commit in a repo?

learning2learn
  • 405
  • 5
  • 11
Grigoriy Mikhalkin
  • 5,035
  • 1
  • 18
  • 36