Move from fmt.Errorf to errors.New

In many cases fmt.Errorf is good enough, but since
error is an interface, you can use arbitrary data
structures as error values, to allow callers to
inspect the details of the error.
This commit is contained in:
Harshavardhana
2015-03-15 19:40:30 -07:00
parent a737246f92
commit 596eeb097e
4 changed files with 29 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
package storage
import (
"errors"
"fmt"
"strconv"
"strings"
@@ -34,7 +35,7 @@ func parseDate(str string) (d Date, err error) {
y, m, n int
)
if len(str) != 10 || str[4] != '-' || str[7] != '-' {
err = fmt.Errorf("Invalid 0000-00-000 style DATE string: " + str)
err = errors.New("Invalid 0000-00-000 style DATE string: " + str)
return
}
if y, err = strconv.Atoi(str[0:4]); err != nil {
@@ -44,14 +45,14 @@ func parseDate(str string) (d Date, err error) {
return
}
if m < 1 || m > 12 {
err = fmt.Errorf("Invalid 0000-00-000 style DATE string: " + str)
err = errors.New("Invalid 0000-00-000 style DATE string: " + str)
return
}
if n, err = strconv.Atoi(str[8:10]); err != nil {
return
}
if n < 1 || n > 31 {
err = fmt.Errorf("Invalid 0000-00-000 style DATE string: " + str)
err = errors.New("Invalid 0000-00-000 style DATE string: " + str)
return
}
d.Year = int16(y)