Error return value is not checked (errcheck)

This commit is contained in:
Arran Ubels 2023-02-15 15:49:18 +11:00 committed by GitHub
parent 26d95ba3e6
commit 5335e6fe23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -28,7 +28,7 @@ func BenchmarkShotgunParse(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
for _, dateStr := range testDates { for _, dateStr := range testDates {
// This is the non dateparse traditional approach // This is the non dateparse traditional approach
parseShotgunStyle(dateStr) _ = parseShotgunStyle(dateStr)
} }
} }
} }
@ -37,7 +37,7 @@ func BenchmarkParseAny(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
for _, dateStr := range testDates { for _, dateStr := range testDates {
ParseAny(dateStr) _ = ParseAny(dateStr)
} }
} }
} }

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/araddon/dateparse module github.com/araddon/dateparse
go 1.12 go 1.19
require ( require (
github.com/mattn/go-runewidth v0.0.10 // indirect github.com/mattn/go-runewidth v0.0.10 // indirect

View File

@ -234,7 +234,10 @@ func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error) {
func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *parser, err error) { func parseTime(datestr string, loc *time.Location, opts ...ParserOption) (p *parser, err error) {
p = newParser(datestr, loc, opts...) p, err = newParser(datestr, loc, opts...)
if err != nil {
return
}
if p.retryAmbiguousDateWithSwap { if p.retryAmbiguousDateWithSwap {
// month out of range signifies that a day/month swap is the correct solution to an ambiguous date // month out of range signifies that a day/month swap is the correct solution to an ambiguous date
// this is because it means that a day is being interpreted as a month and overflowing the valid value for that // this is because it means that a day is being interpreted as a month and overflowing the valid value for that
@ -2008,7 +2011,7 @@ func RetryAmbiguousDateWithSwap(retryAmbiguousDateWithSwap bool) ParserOption {
} }
} }
func newParser(dateStr string, loc *time.Location, opts ...ParserOption) *parser { func newParser(dateStr string, loc *time.Location, opts ...ParserOption) (*parser, error) {
p := &parser{ p := &parser{
stateDate: dateStart, stateDate: dateStart,
stateTime: timeIgnore, stateTime: timeIgnore,
@ -2021,7 +2024,9 @@ func newParser(dateStr string, loc *time.Location, opts ...ParserOption) *parser
// allow the options to mutate the parser fields from their defaults // allow the options to mutate the parser fields from their defaults
for _, option := range opts { for _, option := range opts {
option(p) if err := option(p); err != nil {
return nil, fmt.Sprintf("option error: %w", err)
}
} }
return p return p
} }