How to use failpoint to return two values?
A go function may return multiple values, such as func a() (string, int). In this case, how should I define failpoint variables?
Thank you!
Failpoints by convention only set a single value-- they're not functions. What's your use case?
A go function may return some error code and I want to use fail point to simulate that the function returns an error. But the error code may be returned with other variables together, as a go function allows to return multiple variables. Thanks!
Marshall it into a string:
func whatever() (*someStruct, error) {
...
// gofail: var someData string
// return unmarshalMyData(someData)
...
}
func unmarshalMyData(v string) (*someStruct, error) { ... }
In general there needs to be some custom unmarshalling to return user-provided errors since many packages use singleton error values (e.g., io.EOF) for pointer comparisons. There's no way to get that through reflection as far as I know.
I wouldn't advise extending gofail to support multi-value failpoints directly since it would introduce a lot of complexity. Maybe supporting %q-formatted gob decoding for arbitrary structs would be OK as part of the rewrite rules.
No plan to support this.