feat(logging); improve messages and errors (#336)

* feat(logger): add module context

* feat(logger): change errors package

* feat(logger): update tests
This commit is contained in:
Ludvig Lundgren 2022-07-05 13:31:44 +02:00 committed by GitHub
parent 95471a4cf7
commit 0e88117702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 1172 additions and 957 deletions

View file

@ -3,7 +3,6 @@ package domain
import "context"
type DownloadClientRepo interface {
//FindByActionID(actionID int) ([]DownloadClient, error)
List(ctx context.Context) ([]DownloadClient, error)
FindByID(ctx context.Context, id int32) (*DownloadClient, error)
Store(ctx context.Context, client DownloadClient) (*DownloadClient, error)

View file

@ -14,12 +14,12 @@ import (
"strings"
"time"
"golang.org/x/net/publicsuffix"
"github.com/autobrr/autobrr/pkg/errors"
"github.com/anacrolix/torrent/metainfo"
"github.com/dustin/go-humanize"
"github.com/moistari/rls"
"github.com/pkg/errors"
"golang.org/x/net/publicsuffix"
)
type ReleaseRepo interface {
@ -269,7 +269,7 @@ func (r *Release) DownloadTorrentFile() error {
jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
if err != nil {
return err
return errors.Wrap(err, "could not create cookiejar")
}
customTransport := http.DefaultTransport.(*http.Transport).Clone()
@ -300,7 +300,7 @@ func (r *Release) DownloadTorrentFile() error {
// retry logic
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("error downloading torrent (%v) file (%v) from '%v' - status code: %d", r.TorrentName, r.TorrentURL, r.Indexer, resp.StatusCode)
return errors.New("error downloading torrent (%v) file (%v) from '%v' - status code: %d", r.TorrentName, r.TorrentURL, r.Indexer, resp.StatusCode)
}
// Create tmp file
@ -479,7 +479,7 @@ func getStringMapValue(stringMap map[string]string, key string) (string, error)
}
}
return "", fmt.Errorf("key was not found in map: %q", lowerKey)
return "", errors.New("key was not found in map: %q", lowerKey)
}
func SplitAny(s string, seps string) []string {

View file

@ -3,6 +3,8 @@ package domain
import (
"fmt"
"regexp"
"github.com/autobrr/autobrr/pkg/errors"
)
var types map[string][]*TagInfo
@ -192,7 +194,7 @@ func init() {
var err error
//if info.re, err = regexp.Compile(`(?i)^(?:` + info.RE() + `)$`); err != nil {
if info.re, err = regexp.Compile(`(?i)(?:` + info.RE() + `)`); err != nil {
fmt.Errorf("tag %q has invalid regexp %q\n", s, info.re)
errors.Wrap(err, "tag %q has invalid regexp %q\n", s, info.re)
}
}
}