|
37 | 37 |
|
38 | 38 | // ErrNotArray is returned when the value is not an array. |
39 | 39 | ErrNotArray = errors.NewKind("value of type %T is not an array") |
| 40 | + |
| 41 | + // ErrConvertToSQL is returned when Convert failed. |
| 42 | + // It makes an error less verbose comparingto what spf13/cast returns. |
| 43 | + ErrConvertToSQL = errors.NewKind("incompatible conversion to SQL type: %s") |
40 | 44 | ) |
41 | 45 |
|
42 | 46 | // Schema is the definition of a table. |
@@ -300,7 +304,6 @@ func (t numberT) Convert(v interface{}) (interface{}, error) { |
300 | 304 | default: |
301 | 305 | return nil, ErrInvalidType.New(t.t) |
302 | 306 | } |
303 | | - |
304 | 307 | } |
305 | 308 |
|
306 | 309 | // Compare implements Type interface. |
@@ -505,7 +508,11 @@ func (t textT) SQL(v interface{}) sqltypes.Value { |
505 | 508 |
|
506 | 509 | // Convert implements Type interface. |
507 | 510 | func (t textT) Convert(v interface{}) (interface{}, error) { |
508 | | - return cast.ToStringE(v) |
| 511 | + val, err := cast.ToStringE(v) |
| 512 | + if err != nil { |
| 513 | + return nil, ErrConvertToSQL.New(t) |
| 514 | + } |
| 515 | + return val, nil |
509 | 516 | } |
510 | 517 |
|
511 | 518 | // Compare implements Type interface. |
@@ -534,7 +541,11 @@ func (t booleanT) SQL(v interface{}) sqltypes.Value { |
534 | 541 |
|
535 | 542 | // Convert implements Type interface. |
536 | 543 | func (t booleanT) Convert(v interface{}) (interface{}, error) { |
537 | | - return cast.ToBoolE(v) |
| 544 | + val, err := cast.ToBoolE(v) |
| 545 | + if err != nil { |
| 546 | + return nil, ErrConvertToSQL.New(t) |
| 547 | + } |
| 548 | + return val, nil |
538 | 549 | } |
539 | 550 |
|
540 | 551 | // Compare implements Type interface. |
|
0 commit comments