Skip to content

Commit

Permalink
Rename TypeError to ValueError
Browse files Browse the repository at this point in the history
A TypeError typically refers to the go type of something. This error is
used to indicate that the value cannot be parsed correctly.
  • Loading branch information
thatguystone committed Oct 17, 2018
1 parent 956af8b commit 78e08d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"reflect"
)

// TypeError is an error type returned when param has difficulty deserializing a
// parameter value.
type TypeError struct {
// ValueError is an error type returned when param has difficulty deserializing
// a parameter value.
type ValueError struct {
// The key that was in error.
Key string
// The type that was expected.
Expand All @@ -17,9 +17,9 @@ type TypeError struct {
Err error
}

func (t TypeError) Error() string {
return fmt.Sprintf("param: error parsing key %q as %v: %v", t.Key, t.Type,
t.Err)
func (v ValueError) Error() string {
return fmt.Sprintf("param: error parsing key %q as %v: %v",
v.Key, v.Type, v.Err)
}

// SingletonError is an error type returned when a parameter is passed multiple
Expand Down
10 changes: 5 additions & 5 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func parseTextUnmarshaler(key, keytail string, values []string, target reflect.V
tu := target.Addr().Interface().(encoding.TextUnmarshaler)
err = tu.UnmarshalText([]byte(values[0]))
if err != nil {
return TypeError{
return ValueError{
Key: kpath(key, keytail),
Type: target.Type(),
Err: err,
Expand All @@ -132,7 +132,7 @@ func parseBool(key, keytail string, values []string, target reflect.Value) error
target.SetBool(false)
return nil
default:
return TypeError{
return ValueError{
Key: kpath(key, keytail),
Type: target.Type(),
}
Expand All @@ -148,7 +148,7 @@ func parseInt(key, keytail string, values []string, target reflect.Value) error

i, err := strconv.ParseInt(values[0], 10, t.Bits())
if err != nil {
return TypeError{
return ValueError{
Key: kpath(key, keytail),
Type: t,
Err: err.(*strconv.NumError).Err,
Expand All @@ -168,7 +168,7 @@ func parseUint(key, keytail string, values []string, target reflect.Value) error

i, err := strconv.ParseUint(values[0], 10, t.Bits())
if err != nil {
return TypeError{
return ValueError{
Key: kpath(key, keytail),
Type: t,
Err: err.(*strconv.NumError).Err,
Expand All @@ -188,7 +188,7 @@ func parseFloat(key, keytail string, values []string, target reflect.Value) erro

f, err := strconv.ParseFloat(values[0], t.Bits())
if err != nil {
return TypeError{
return ValueError{
Key: kpath(key, keytail),
Type: t,
Err: err.(*strconv.NumError).Err,
Expand Down

0 comments on commit 78e08d0

Please sign in to comment.