commit 54640ca00f76c1b4298c39a494603a3468c916b3 from: Oliver Lowe date: Tue Apr 29 23:45:16 2025 UTC internal/db: return error on channel not found Defining a new error as I imagine we'll be wanting to handle this explicitly e.g. by trying to look up a feed on the web. commit - 4b027dd5ebf86a899817b235cb999dc9cd37f2a8 commit + 54640ca00f76c1b4298c39a494603a3468c916b3 blob - e13d3e5bec8d3e544e132b865037605b3202a231 blob + d703d35406a6ac437561fcde96b4bc3023beb867 --- internal/db/channels.go +++ internal/db/channels.go @@ -2,6 +2,7 @@ package db import ( "encoding/json" + "errors" "github.com/streatCodes/rss/rss" bolt "go.etcd.io/bbolt" @@ -27,12 +28,17 @@ func (db *DB) SaveChannel(url string, channel *rss.Cha return err } +var ErrNotExist = errors.New("channel does not exist") + func (db *DB) GetChannel(url string) (*rss.Channel, error) { var channelBytes []byte err := db.raw.View(func(tx *bolt.Tx) error { if bucket := tx.Bucket(channelsBucket); bucket != nil { channelBytes = bucket.Get([]byte(url)) } + if len(channelBytes) == 0 { + return ErrNotExist + } return nil })