Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Make conversion error clearer and less detailed. #556

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions sql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var (

// ErrNotArray is returned when the value is not an array.
ErrNotArray = errors.NewKind("value of type %T is not an array")

// ErrConvertToSQL is returned when Convert failed.
// It makes an error less verbose comparingto what spf13/cast returns.
ErrConvertToSQL = errors.NewKind("incompatible conversion to SQL type: %s")
)

// Schema is the definition of a table.
Expand Down Expand Up @@ -300,7 +304,6 @@ func (t numberT) Convert(v interface{}) (interface{}, error) {
default:
return nil, ErrInvalidType.New(t.t)
}

}

// Compare implements Type interface.
Expand Down Expand Up @@ -505,7 +508,11 @@ func (t textT) SQL(v interface{}) sqltypes.Value {

// Convert implements Type interface.
func (t textT) Convert(v interface{}) (interface{}, error) {
return cast.ToStringE(v)
val, err := cast.ToStringE(v)
if err != nil {
return nil, ErrConvertToSQL.New(t)
}
return val, nil
}

// Compare implements Type interface.
Expand Down Expand Up @@ -534,7 +541,11 @@ func (t booleanT) SQL(v interface{}) sqltypes.Value {

// Convert implements Type interface.
func (t booleanT) Convert(v interface{}) (interface{}, error) {
return cast.ToBoolE(v)
val, err := cast.ToBoolE(v)
if err != nil {
return nil, ErrConvertToSQL.New(t)
}
return val, nil
}

// Compare implements Type interface.
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy