Skip to content

Commit 1387632

Browse files
committed
use %w for errors from feed query builder. use errors.Is to check sql errors in storage/feed.go
1 parent b99cd91 commit 1387632

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

storage/feed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (s *Storage) WeeklyFeedEntryCount(userID, feedID int64) (int, error) {
143143
err := s.db.QueryRow(query, userID, feedID).Scan(&weeklyCount)
144144

145145
switch {
146-
case err == sql.ErrNoRows:
146+
case errors.Is(err, sql.ErrNoRows):
147147
return 0, nil
148148
case err != nil:
149149
return 0, fmt.Errorf(`store: unable to fetch weekly count for feed #%d: %v`, feedID, err)
@@ -159,7 +159,7 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
159159
feed, err := builder.GetFeed()
160160

161161
switch {
162-
case err == sql.ErrNoRows:
162+
case errors.Is(err, sql.ErrNoRows):
163163
return nil, nil
164164
case err != nil:
165165
return nil, fmt.Errorf(`store: unable to fetch feed #%d: %v`, feedID, err)

storage/feed_query_builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) {
179179

180180
rows, err := f.store.db.Query(query, f.args...)
181181
if err != nil {
182-
return nil, fmt.Errorf(`store: unable to fetch feeds: %v`, err)
182+
return nil, fmt.Errorf(`store: unable to fetch feeds: %w`, err)
183183
}
184184
defer rows.Close()
185185

@@ -224,7 +224,7 @@ func (f *FeedQueryBuilder) GetFeeds() (model.Feeds, error) {
224224
)
225225

226226
if err != nil {
227-
return nil, fmt.Errorf(`store: unable to fetch feeds row: %v`, err)
227+
return nil, fmt.Errorf(`store: unable to fetch feeds row: %w`, err)
228228
}
229229

230230
if iconID != nil {
@@ -275,7 +275,7 @@ func (f *FeedQueryBuilder) fetchFeedCounter() (unreadCounters map[int64]int, rea
275275

276276
rows, err := f.store.db.Query(query, f.counterArgs...)
277277
if err != nil {
278-
return nil, nil, fmt.Errorf(`store: unable to fetch feed counts: %v`, err)
278+
return nil, nil, fmt.Errorf(`store: unable to fetch feed counts: %w`, err)
279279
}
280280
defer rows.Close()
281281

@@ -286,7 +286,7 @@ func (f *FeedQueryBuilder) fetchFeedCounter() (unreadCounters map[int64]int, rea
286286
var status string
287287
var count int
288288
if err := rows.Scan(&feedID, &status, &count); err != nil {
289-
return nil, nil, fmt.Errorf(`store: unable to fetch feed counter row: %v`, err)
289+
return nil, nil, fmt.Errorf(`store: unable to fetch feed counter row: %w`, err)
290290
}
291291

292292
if status == model.EntryStatusRead {

0 commit comments

Comments
 (0)