🐛 Protect from nil pointers

This commit is contained in:
Dan Jones 2024-10-23 22:22:41 -05:00
commit a9fe6f30fc

View file

@ -10,11 +10,15 @@ import (
)
var ErrNoName = errors.New("missing name")
var ErrNilPointer = errors.New("nil pointer")
var animePattern = `^\[.+\] `
var animeRegexp = regexp.MustCompile(animePattern)
func (s *Show) Match(path string) (bool, error) {
if s == nil {
return false, ErrNilPointer
}
if s.Pattern != "" {
return s.matchRegexp(path)
}
@ -50,12 +54,15 @@ func (s *Show) matchRegexp(path string) (f bool, err error) {
}
func (ss *Shows) All() iter.Seq[*Show] {
if ss == nil {
return func(func(*Show) bool) {}
}
return slices.Values(*ss)
}
func (d *Data) AllShows(silent bool) iter.Seq[*Show] {
return func(yield func(*Show) bool) {
if d.Config == nil {
if d == nil || d.Config == nil {
return
}
for _, show := range d.Config.Shows {