You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is bug is in the generation code, specifically the way we inline the private error type rather than naming it. Take the example of the following definition:
The above definition would generate roughly the following:
type myError {
Code int
Message string
}
type MyError struct {
errorInstanceID uuid.UUID
myError
cause error
stack werror.StackTrace
}
The collision occurs on the generated SafeParams method.
// safeParams returns a set of named safe parameters detailing this particular error instance.
func (e *MyError) safeParams() map[string]interface{} {
return map[string]interface{}{"code": e.Code, "message": e.Message, "errorInstanceId": e.errorInstanceID}
}
Because Code and Message are also methods on MyError, this actually returns functions rather than the values stored on myError.
Think the fix is just to name the internal error type on the exported error type - I don't see any reason this needs to be inlined.
The text was updated successfully, but these errors were encountered:
Today I think you can access the struct fields directly like myErr.Message because the fields are embedded, so I think this would be a breaking change if we don't mitigate that somehow. I wonder if we should add some kind of prefix in the case of conflict with the interface methods
Interesting. In a way, that's even stranger/potentially more problematic, since the internal fields would also be shaded by the Message and Code methods whenever a collision occurs.
A simple non-breaking workaround for the safe params issue would be:
I'll probably contribute ^ either way when I get a chance. But at some point we probably need to revisit and potentially do a break to address all the potential collisions. There is at least one other issue tracked for a name collision on generated errors (e.g., #78) and I bet I could think of a couple more if I took a harder look.
There is bug is in the generation code, specifically the way we inline the private error type rather than naming it. Take the example of the following definition:
The above definition would generate roughly the following:
The collision occurs on the generated
SafeParams
method.Because
Code
andMessage
are also methods onMyError
, this actually returns functions rather than the values stored onmyError
.Think the fix is just to name the internal error type on the exported error type - I don't see any reason this needs to be inlined.
The text was updated successfully, but these errors were encountered: