delete multierr
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package multierr
|
||||
|
||||
import "strings"
|
||||
|
||||
type Err struct {
|
||||
errs []error
|
||||
}
|
||||
|
||||
func (me *Err) Error() string {
|
||||
var builder strings.Builder
|
||||
for _, err := range me.errs {
|
||||
builder.WriteString("\n")
|
||||
builder.WriteString(err.Error())
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func (me *Err) Errors() []error {
|
||||
return me.errs
|
||||
}
|
||||
|
||||
func (me *Err) Len() int {
|
||||
return len(me.errs)
|
||||
}
|
||||
|
||||
func (me *Err) Add(err error) {
|
||||
me.errs = append(me.errs, err)
|
||||
}
|
||||
|
||||
func (me *Err) Extend(errs []error) {
|
||||
me.errs = append(me.errs, errs...)
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/mime"
|
||||
"go.senan.xyz/gonic/multierr"
|
||||
"go.senan.xyz/gonic/scanner/tags"
|
||||
)
|
||||
|
||||
@@ -327,28 +326,27 @@ func (p *Podcasts) RefreshPodcasts() error {
|
||||
if err := p.db.Find(&podcasts).Error; err != nil {
|
||||
return fmt.Errorf("find podcasts: %w", err)
|
||||
}
|
||||
var errs *multierr.Err
|
||||
if errors.As(p.refreshPodcasts(podcasts), &errs) && errs.Len() > 0 {
|
||||
return fmt.Errorf("refresh podcasts: %w", errs)
|
||||
if err := p.refreshPodcasts(podcasts); err != nil {
|
||||
return fmt.Errorf("refresh podcasts: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Podcasts) refreshPodcasts(podcasts []*db.Podcast) error {
|
||||
errs := &multierr.Err{}
|
||||
var errs []error
|
||||
for _, podcast := range podcasts {
|
||||
fp := gofeed.NewParser()
|
||||
feed, err := fp.ParseURL(podcast.URL)
|
||||
if err != nil {
|
||||
errs.Add(fmt.Errorf("refreshing podcast with url %q: %w", podcast.URL, err))
|
||||
errs = append(errs, fmt.Errorf("refreshing podcast with url %q: %w", podcast.URL, err))
|
||||
continue
|
||||
}
|
||||
if err = p.AddNewEpisodes(podcast, feed.Items); err != nil {
|
||||
errs.Add(fmt.Errorf("adding episodes: %w", err))
|
||||
errs = append(errs, fmt.Errorf("adding episodes: %w", err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
return errs
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func (p *Podcasts) DownloadPodcastAll(podcastID int) error {
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/mime"
|
||||
"go.senan.xyz/gonic/multierr"
|
||||
"go.senan.xyz/gonic/scanner/tags"
|
||||
)
|
||||
|
||||
@@ -81,7 +80,6 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) {
|
||||
|
||||
start := time.Now()
|
||||
c := &Context{
|
||||
errs: &multierr.Err{},
|
||||
seenTracks: map[int]struct{}{},
|
||||
seenAlbums: map[int]struct{}{},
|
||||
isFull: opts.IsFull,
|
||||
@@ -90,7 +88,7 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) {
|
||||
log.Println("starting scan")
|
||||
defer func() {
|
||||
log.Printf("finished scan in %s, +%d/%d tracks (%d err)\n",
|
||||
durSince(start), c.SeenTracksNew(), c.SeenTracks(), c.errs.Len())
|
||||
durSince(start), c.SeenTracksNew(), c.SeenTracks(), len(c.errs))
|
||||
}()
|
||||
|
||||
for _, dir := range s.musicDirs {
|
||||
@@ -119,11 +117,7 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*Context, error) {
|
||||
return nil, fmt.Errorf("set scan time: %w", err)
|
||||
}
|
||||
|
||||
if c.errs.Len() > 0 {
|
||||
return c, c.errs
|
||||
}
|
||||
|
||||
return c, nil
|
||||
return c, errors.Join(c.errs...)
|
||||
}
|
||||
|
||||
func (s *Scanner) ExecuteWatch() error {
|
||||
@@ -159,7 +153,6 @@ func (s *Scanner) ExecuteWatch() error {
|
||||
}
|
||||
for dirName := range scanList {
|
||||
c := &Context{
|
||||
errs: &multierr.Err{},
|
||||
seenTracks: map[int]struct{}{},
|
||||
seenAlbums: map[int]struct{}{},
|
||||
isFull: false,
|
||||
@@ -240,7 +233,7 @@ func (s *Scanner) watchCallback(dir string, absPath string, d fs.DirEntry, err e
|
||||
|
||||
func (s *Scanner) scanCallback(c *Context, dir string, absPath string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
c.errs.Add(err)
|
||||
c.errs = append(c.errs, err)
|
||||
return nil
|
||||
}
|
||||
if dir == absPath {
|
||||
@@ -268,7 +261,7 @@ func (s *Scanner) scanCallback(c *Context, dir string, absPath string, d fs.DirE
|
||||
|
||||
tx := s.db.Begin()
|
||||
if err := s.scanDir(tx, c, dir, absPath); err != nil {
|
||||
c.errs.Add(fmt.Errorf("%q: %w", absPath, err))
|
||||
c.errs = append(c.errs, fmt.Errorf("%q: %w", absPath, err))
|
||||
tx.Rollback()
|
||||
return nil
|
||||
}
|
||||
@@ -648,7 +641,7 @@ func durSince(t time.Time) time.Duration {
|
||||
}
|
||||
|
||||
type Context struct {
|
||||
errs *multierr.Err
|
||||
errs []error
|
||||
isFull bool
|
||||
|
||||
seenTracks map[int]struct{}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/mockfs"
|
||||
"go.senan.xyz/gonic/multierr"
|
||||
"go.senan.xyz/gonic/scanner"
|
||||
)
|
||||
|
||||
@@ -523,16 +522,20 @@ func TestTagErrors(t *testing.T) {
|
||||
return scanner.ErrReadingTags
|
||||
})
|
||||
|
||||
var errs *multierr.Err
|
||||
ctx, err := m.ScanAndCleanErr()
|
||||
errs, ok := err.(interface{ Unwrap() []error })
|
||||
require.True(ok)
|
||||
|
||||
require.ErrorAs(err, &errs)
|
||||
require.Equal(2, errs.Len()) // we have 2 dir errors
|
||||
require.Equal(2, len(errs.Unwrap())) // we have 2 dir errors
|
||||
require.Equal(m.NumTracks()-(3*2), ctx.SeenTracks()) // we saw all tracks bar 2 album contents
|
||||
require.Equal(m.NumTracks()-(3*2), ctx.SeenTracksNew()) // we have all tracks bar 2 album contents
|
||||
|
||||
ctx, err = m.ScanAndCleanErr()
|
||||
require.ErrorAs(err, &errs)
|
||||
require.Equal(2, errs.Len()) // we have 2 dir errors
|
||||
errs, ok = err.(interface{ Unwrap() []error })
|
||||
require.True(ok)
|
||||
|
||||
require.Equal(2, len(errs.Unwrap())) // we have 2 dir errors
|
||||
require.Equal(m.NumTracks()-(3*2), ctx.SeenTracks()) // we saw all tracks bar 2 album contents
|
||||
require.Equal(0, ctx.SeenTracksNew()) // we have no new tracks
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/multierr"
|
||||
"go.senan.xyz/gonic/scanner"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
|
||||
@@ -73,14 +72,14 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {
|
||||
return spec.NewError(0, "error updating stats: %v", err)
|
||||
}
|
||||
|
||||
var scrobbleErrs multierr.Err
|
||||
var scrobbleErrs []error
|
||||
for _, scrobbler := range c.Scrobblers {
|
||||
if err := scrobbler.Scrobble(user, track, optStamp, optSubmission); err != nil {
|
||||
scrobbleErrs.Add(err)
|
||||
scrobbleErrs = append(scrobbleErrs, err)
|
||||
}
|
||||
}
|
||||
if scrobbleErrs.Len() > 0 {
|
||||
return spec.NewError(0, "error when submitting: %s", scrobbleErrs.Error())
|
||||
if len(scrobbleErrs) > 0 {
|
||||
return spec.NewError(0, "error when submitting: %v", errors.Join(scrobbleErrs...))
|
||||
}
|
||||
|
||||
return spec.NewResponse()
|
||||
|
||||
Reference in New Issue
Block a user