Merge d3b49c3d235b670ba7fb2d5558dfa48033f7b9d8 into 4e34a6d21b63e9a9b701a70be9759e5539bf26e9

This commit is contained in:
iseki 2025-08-21 07:38:52 +07:00 committed by GitHub
commit 80c8015d23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -946,6 +946,22 @@ func (field *Field) setupValuerAndSetter(modelType reflect.Type) {
}
}
}
var oldSetter = field.Set
field.Set = func(ctx context.Context, value reflect.Value, v interface{}) (err error) {
err = oldSetter(ctx, value, v)
if err == nil {
return
}
var errMessage = err.Error()
// It's ugly and unrobust, but it's required since the fallbackSetter create error by fmt.Errorf directly and here are some nested setter calls.
// Without string manipulation, there's no way to avoid a duplicated error message.
// Also, adding many fmt.Errorf calls in all setter implementations is not a good idea, apparently.
if strings.Contains(errMessage, "to field "+field.Name) {
return
}
err = fmt.Errorf("failed to set value to field %s: %w", field.Name, err)
return
}
if field.Serializer != nil {
var (