may want to evaluate st.Message() before the return statement
157 if sst != nil {
158 return sst, sst.Message(), sst.Err()
159 }
160 return st, st.Message(), st.Err()161}
162
163func FromError(err error) (st *Status, ok bool) {
may want to evaluate st.Err() before the return statement
157 if sst != nil {
158 return sst, sst.Message(), sst.Err()
159 }
160 return st, st.Message(), st.Err()161}
162
163func FromError(err error) (st *Status, ok bool) {
may want to evaluate sst.Message() before the return statement
155
156 sst := withDetails(st, err, details...)
157 if sst != nil {
158 return sst, sst.Message(), sst.Err()159 }
160 return st, st.Message(), st.Err()
161}
may want to evaluate sst.Err() before the return statement
155
156 sst := withDetails(st, err, details...)
157 if sst != nil {
158 return sst, sst.Message(), sst.Err()159 }
160 return st, st.Message(), st.Err()
161}
Description
Depending on the evaluation order is not idiomatic and may lead to bugs during future refactorings.
Bad practice
package main
func mutate(x *int) int {
*x += 10
return *x
}
func identity(x int) int {
return x
}
func foo() (int, int, int) {
x := 5
return identity(x), mutate(&x), x // 5, 15, 15
}
Recommended
package main
func mutate(x *int) int {
*x += 10
return *x
}
func identity(x int) int {
return x
}
func foo() (int, int, int) {
x := 5
result := mutate(&x)
return identity(x), result, x // 15, 15, 15
}