|
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. |
@@ -309,7 +313,6 @@ func (t numberT) Convert(v interface{}) (interface{}, error) { |
309 | 313 | default: |
310 | 314 | return nil, ErrInvalidType.New(t.t) |
311 | 315 | } |
312 | | - |
313 | 316 | } |
314 | 317 |
|
315 | 318 | // Compare implements Type interface. |
@@ -526,7 +529,11 @@ func (t textT) SQL(v interface{}) sqltypes.Value { |
526 | 529 |
|
527 | 530 | // Convert implements Type interface. |
528 | 531 | func (t textT) Convert(v interface{}) (interface{}, error) { |
529 | | - return cast.ToStringE(v) |
| 532 | + val, err := cast.ToStringE(v) |
| 533 | + if err != nil { |
| 534 | + return nil, ErrConvertToSQL.New(t) |
| 535 | + } |
| 536 | + return val, nil |
530 | 537 | } |
531 | 538 |
|
532 | 539 | // Compare implements Type interface. |
@@ -559,7 +566,11 @@ func (t booleanT) SQL(v interface{}) sqltypes.Value { |
559 | 566 |
|
560 | 567 | // Convert implements Type interface. |
561 | 568 | func (t booleanT) Convert(v interface{}) (interface{}, error) { |
562 | | - return cast.ToBoolE(v) |
| 569 | + val, err := cast.ToBoolE(v) |
| 570 | + if err != nil { |
| 571 | + return nil, ErrConvertToSQL.New(t) |
| 572 | + } |
| 573 | + return val, nil |
563 | 574 | } |
564 | 575 |
|
565 | 576 | // Compare implements Type interface. |
|
0 commit comments