Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
better error handling at sqlite3.go
Browse files Browse the repository at this point in the history
  • Loading branch information
boramalper committed Dec 30, 2018
1 parent e7f5fb0 commit e01a3be
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/persistence/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (db *sqlite3Database) QueryTorrents(
queryArgs = append(queryArgs, limit)

rows, err := db.conn.Query(sqlQuery, queryArgs...)
defer rows.Close()
defer closeRows(rows)
if err != nil {
return nil, errors.Wrap(err, "query error")
}
Expand Down Expand Up @@ -375,7 +375,7 @@ func (db *sqlite3Database) GetTorrent(infoHash []byte) (*TorrentMetadata, error)
WHERE info_hash = ?`,
infoHash,
)
defer rows.Close()
defer closeRows(rows)
if err != nil {
return nil, err
}
Expand All @@ -396,7 +396,7 @@ func (db *sqlite3Database) GetFiles(infoHash []byte) ([]File, error) {
rows, err := db.conn.Query(
"SELECT size, path FROM files, torrents WHERE files.torrent_id = torrents.id AND torrents.info_hash = ?;",
infoHash)
defer rows.Close()
defer closeRows(rows)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -453,7 +453,7 @@ func (db *sqlite3Database) GetStatistics(from string, n uint) (*Statistics, erro
GROUP BY dt;`,
timef),
fromTime.Unix(), toTime.Unix())
defer rows.Close()
defer closeRows(rows)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -687,3 +687,9 @@ func executeTemplate(text string, data interface{}, funcs template.FuncMap) stri
}
return buf.String()
}

func closeRows(rows *sql.Rows) {
if err := rows.Close(); err != nil {
zap.L().Error("could not close row", zap.Error(err))
}
}

0 comments on commit e01a3be

Please sign in to comment.