Closed jackwilsdon closed 9 months ago
I 100% agree with you. The concern right now is if i added it, it would be a breaking change. I will think about this and see how "harmful" adding it might be.
I don't think introducing an additional interface would be a breaking change?
If you go from
Fake(faker *Faker) interface{}
to
Fake(faker *Faker) (interface{}, error)
Then yes it would technically be a breaking change.
Does implementing it like this not make it backwards compatible? https://go.dev/play/p/GxOzKQxjO7D
I dont really want to implement and maintain both. I might just pull the trigger and change it.
I'm happy to open a PR for this if you're happy with the linked implemention (i.e. introducing a new interface). It should only be a couple of lines of code in isFakeable
and callFake
and have a low maintenance burden. It'd be nice to keep backwards compatibility if possible.
It really should just have the error in there.
It'd be useful if errors could be returned from fakeables, in the event that they call other functions which may return an error (e.g.
faker.Struct
to fake a sub-struct).A new interface could be introduced for this:
Which could be used in
isFakeable
andcallFake
.Alternatively,
callFake
could be updated to add special handling for theerror
type being returned in place of a value.