mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: improve error message for GoType (#969)
This commit is contained in:
@@ -945,6 +945,9 @@ func (d *Descriptor) goType(typ interface{}, expectType reflect.Type) {
|
||||
}
|
||||
default:
|
||||
d.err = fmt.Errorf("GoType must be a %q type or ValueScanner", expectType)
|
||||
if pt := reflect.PtrTo(t); pt.Implements(valueScannerType) {
|
||||
d.err = fmt.Errorf("%s. Use %s instead", d.err, pt)
|
||||
}
|
||||
}
|
||||
d.Info = info
|
||||
}
|
||||
|
||||
@@ -80,8 +80,10 @@ func TestInt(t *testing.T) {
|
||||
assert.True(t, fd.Info.Nillable)
|
||||
assert.True(t, fd.Info.ValueScanner())
|
||||
|
||||
fd = field.Int("count").GoType(sql.NullInt64{}).Descriptor()
|
||||
assert.EqualError(t, fd.Err(), `GoType must be a "int" type or ValueScanner. Use *sql.NullInt64 instead`)
|
||||
fd = field.Int("count").GoType(false).Descriptor()
|
||||
assert.Error(t, fd.Err())
|
||||
assert.EqualError(t, fd.Err(), `GoType must be a "int" type or ValueScanner`)
|
||||
fd = field.Int("count").GoType(struct{}{}).Descriptor()
|
||||
assert.Error(t, fd.Err())
|
||||
fd = field.Int("count").GoType(new(Count)).Descriptor()
|
||||
|
||||
Reference in New Issue
Block a user