Browse Source

Add more details in feed storage errors to facilitate debugging

Frédéric Guillot 4 months ago
parent
commit
74c35ad000
3 changed files with 17 additions and 17 deletions
  1. 1 1
      storage/enclosure.go
  2. 10 10
      storage/entry.go
  3. 6 6
      storage/feed.go

+ 1 - 1
storage/enclosure.go

@@ -64,7 +64,7 @@ func (s *Storage) CreateEnclosure(enclosure *model.Enclosure) error {
 	).Scan(&enclosure.ID)
 
 	if err != nil {
-		return fmt.Errorf("unable to create enclosure: %v", err)
+		return fmt.Errorf("unable to create enclosure %q: %v", enclosure.URL, err)
 	}
 
 	return nil

+ 10 - 10
storage/entry.go

@@ -23,7 +23,7 @@ func (s *Storage) CountUnreadEntries(userID int64) int {
 
 	n, err := builder.CountEntries()
 	if err != nil {
-		logger.Error("unable to count unread entries: %v", err)
+		logger.Error("unable to count unread entries for user #%d: %v", userID, err)
 		return 0
 	}
 
@@ -45,7 +45,7 @@ func (s *Storage) UpdateEntryContent(entry *model.Entry) error {
 	_, err = tx.Exec(`UPDATE entries SET content=$1 WHERE id=$2 AND user_id=$3`, entry.Content, entry.ID, entry.UserID)
 	if err != nil {
 		tx.Rollback()
-		return err
+		return fmt.Errorf(`unable to update content of entry #%d: %v`, entry.ID, err)
 	}
 
 	query := `
@@ -56,7 +56,7 @@ func (s *Storage) UpdateEntryContent(entry *model.Entry) error {
 	_, err = tx.Exec(query, entry.ID, entry.UserID)
 	if err != nil {
 		tx.Rollback()
-		return err
+		return fmt.Errorf(`unable to update content of entry #%d: %v`, entry.ID, err)
 	}
 
 	return tx.Commit()
@@ -85,7 +85,7 @@ func (s *Storage) createEntry(entry *model.Entry) error {
 	).Scan(&entry.ID, &entry.Status)
 
 	if err != nil {
-		return fmt.Errorf("unable to create entry: %v", err)
+		return fmt.Errorf("unable to create entry %q (feed #%d): %v", entry.URL, entry.FeedID, err)
 	}
 
 	for i := 0; i < len(entry.Enclosures); i++ {
@@ -124,7 +124,7 @@ func (s *Storage) updateEntry(entry *model.Entry) error {
 	).Scan(&entry.ID)
 
 	if err != nil {
-		return err
+		return fmt.Errorf(`unable to update entry %q: %v`, entry.URL, err)
 	}
 
 	for _, enclosure := range entry.Enclosures {
@@ -180,7 +180,7 @@ func (s *Storage) UpdateEntries(userID, feedID int64, entries model.Entries, upd
 	}
 
 	if err := s.cleanupEntries(feedID, entryHashes); err != nil {
-		logger.Error("[Storage:CleanupEntries] %v", err)
+		logger.Error("[Storage:CleanupEntries] feed #%d: %v", feedID, err)
 	}
 
 	return nil
@@ -206,12 +206,12 @@ func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string
 	query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND id=ANY($3)`
 	result, err := s.db.Exec(query, status, userID, pq.Array(entryIDs))
 	if err != nil {
-		return fmt.Errorf("unable to update entries status: %v", err)
+		return fmt.Errorf("unable to update entries statuses %v: %v", entryIDs, err)
 	}
 
 	count, err := result.RowsAffected()
 	if err != nil {
-		return fmt.Errorf("unable to update these entries: %v", err)
+		return fmt.Errorf("unable to update these entries %v: %v", entryIDs, err)
 	}
 
 	if count == 0 {
@@ -228,12 +228,12 @@ func (s *Storage) ToggleBookmark(userID int64, entryID int64) error {
 	query := `UPDATE entries SET starred = NOT starred WHERE user_id=$1 AND id=$2`
 	result, err := s.db.Exec(query, userID, entryID)
 	if err != nil {
-		return fmt.Errorf("unable to toggle bookmark flag: %v", err)
+		return fmt.Errorf("unable to toggle bookmark flag for entry #%d: %v", entryID, err)
 	}
 
 	count, err := result.RowsAffected()
 	if err != nil {
-		return fmt.Errorf("unable to toogle bookmark flag: %v", err)
+		return fmt.Errorf("unable to toogle bookmark flag for entry #%d: %v", entryID, err)
 	}
 
 	if count == 0 {

+ 6 - 6
storage/feed.go

@@ -80,7 +80,7 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
 
 	rows, err := s.db.Query(query, userID)
 	if err != nil {
-		return nil, fmt.Errorf("Unable to fetch feeds: %v", err)
+		return nil, fmt.Errorf("unable to fetch feeds: %v", err)
 	}
 	defer rows.Close()
 
@@ -180,7 +180,7 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
 	case err == sql.ErrNoRows:
 		return nil, nil
 	case err != nil:
-		return nil, fmt.Errorf("unable to fetch feed: %v", err)
+		return nil, fmt.Errorf("unable to fetch feed #%d: %v", feedID, err)
 	}
 
 	if iconID != nil {
@@ -216,7 +216,7 @@ func (s *Storage) CreateFeed(feed *model.Feed) error {
 		feed.Password,
 	).Scan(&feed.ID)
 	if err != nil {
-		return fmt.Errorf("unable to create feed: %v", err)
+		return fmt.Errorf("unable to create feed %q: %v", feed.FeedURL, err)
 	}
 
 	for i := 0; i < len(feed.Entries); i++ {
@@ -262,7 +262,7 @@ func (s *Storage) UpdateFeed(feed *model.Feed) (err error) {
 	)
 
 	if err != nil {
-		return fmt.Errorf("Unable to update feed: %v", err)
+		return fmt.Errorf("unable to update feed #%d (%s): %v", feed.ID, feed.FeedURL, err)
 	}
 
 	return nil
@@ -274,12 +274,12 @@ func (s *Storage) RemoveFeed(userID, feedID int64) error {
 
 	result, err := s.db.Exec("DELETE FROM feeds WHERE id = $1 AND user_id = $2", feedID, userID)
 	if err != nil {
-		return fmt.Errorf("Unable to remove this feed: %v", err)
+		return fmt.Errorf("unable to remove feed #%d: %v", feedID, err)
 	}
 
 	count, err := result.RowsAffected()
 	if err != nil {
-		return fmt.Errorf("Unable to remove this feed: %v", err)
+		return fmt.Errorf("unable to remove feed #%d: %v", feedID, err)
 	}
 
 	if count == 0 {