maxbrunsfeld / counterfeiter

A tool for generating self-contained, type-safe test doubles in go
MIT License
979 stars 93 forks source link

cannot use json.Marshal(h) (value of type []byte) as driver.Value value in return statement #238

Closed evanchaoli closed 1 year ago

evanchaoli commented 1 year ago

I abstract the problem with the following code:

package utils

import (
    "database/sql/driver"
    "encoding/json"
)

//go:generate counterfeiter . Some
type Some interface {
    Getter() (driver.Value, error)
}

type some struct{}

func (s some) Getter() (driver.Value, error) {
    h := map[string]string{}
    return json.Marshal(h)
}

The error is:

utils/a.go:17:9: cannot use json.Marshal(h) (value of type []byte) as driver.Value value in return statement
utils/a.go:8: running "counterfeiter": exit status 1

The type driver.Value is ultimately just interface{}.

This used to work. An Concourse issue is caused by this issue.

Any idea?

evanchaoli commented 1 year ago

I have found the solution, changing go:generate counterfeiter to counterfeiter:generate fixed the error.