Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Faking a UUID panics #39

Closed
msorens opened this issue Oct 7, 2018 · 3 comments · Fixed by #40
Closed

Faking a UUID panics #39

msorens opened this issue Oct 7, 2018 · 3 comments · Fixed by #40

Comments

@msorens
Copy link
Contributor

msorens commented Oct 7, 2018

I had a complex struct generating a panic from faker and I isolated it to the uuid field causing the issue.
Here's the minimal code to show the error:

package main

import (
	"github.com/bxcodec/faker"
	"github.com/gofrs/uuid"
	"fmt"
)

func main() {
	var u uuid.UUID
	faker.FakeData(&u)
	fmt.Println(u)
}

And the error trace is:

panic: reflect.MakeSlice of non-slice type

goroutine 1 [running]:
reflect.MakeSlice(0x11367c0, 0x1104fe0, 0x58, 0x58, 0xc420065cc8, 0xc420065cd8, 0x1010068)
	/usr/local/Cellar/go/1.10.3/libexec/src/reflect/value.go:2092 +0x1ce
github.com/bxcodec/faker.getValue(0x11367c0, 0x1104fe0, 0x1104fe0, 0xc4200aa250, 0x16, 0x0, 0x10)
	/Users/msorens/code/go/src/github.com/bxcodec/faker/faker.go:218 +0x7a9
github.com/bxcodec/faker.FakeData(0x110c840, 0xc4200aa250, 0xc42008a058, 0x0)
	/Users/msorens/code/go/src/github.com/bxcodec/faker/faker.go:145 +0x1bc
main.main()
	/Users/msorens/code/go/src/github.com/me/fake/tryfake.go:11 +0x4b
exit status 2
@martinbergpetersen
Copy link
Contributor

This is not possible. See PR #40

This will enable faking UUID in the future.

@DenLilleMand
Copy link
Contributor

This is not possible. See PR #40

This will enable faking UUID in the future.

Not the way you're doing it though, if you have a third party package like that one inside of your struct i would suggest you do

type Herp struct {
 ID uuid `faker:"-"`
}

And then

herp := Herp{}
err := FakeData(&herp)
...
herp.ID =  // use the uuid package manually to create a new uuid

If you use the PR you have to use a

type Herp struct {
 ID string `faker:"uuid_hyphenated"`
}

and then

herp := Herp{}
err := FakeData(&herp)
...
should work. 

@msorens
Copy link
Contributor Author

msorens commented Oct 8, 2018

@DenLilleMand : I like the idea of telling faker to just skip that field, rather than changing it to a string. Had not seen the "skip" annotation in the list of available choices. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants