diff --git a/pkg/ketchup/security.go b/pkg/ketchup/security.go index 21d654f1..94f3548b 100644 --- a/pkg/ketchup/security.go +++ b/pkg/ketchup/security.go @@ -45,13 +45,13 @@ func (a App) generateToken(ctx context.Context) (securityPayload, error) { token, err := uuid.New() if err != nil { - return securityPayload{}, fmt.Errorf("generate uuid: %s", err) + return securityPayload{}, fmt.Errorf("generate uuid: %w", err) } id := questionID.Int64() if err := a.redisApp.Store(ctx, tokenKey(token), fmt.Sprintf("%d", id), time.Minute*5); err != nil { - return securityPayload{}, fmt.Errorf("store token: %s", err) + return securityPayload{}, fmt.Errorf("store token: %w", err) } return securityPayload{ diff --git a/pkg/model/repository.go b/pkg/model/repository.go index 2a59d744..7975e36e 100644 --- a/pkg/model/repository.go +++ b/pkg/model/repository.go @@ -61,12 +61,12 @@ func (r *RepositoryKind) UnmarshalJSON(b []byte) error { var strValue string err := json.Unmarshal(b, &strValue) if err != nil { - return fmt.Errorf("unmarshal event type: %s", err) + return fmt.Errorf("unmarshal event type: %w", err) } value, err := ParseRepositoryKind(strValue) if err != nil { - return fmt.Errorf("parse event type: %s", err) + return fmt.Errorf("parse event type: %w", err) } *r = value diff --git a/pkg/model/semver.go b/pkg/model/semver.go index 714c8820..c6443712 100644 --- a/pkg/model/semver.go +++ b/pkg/model/semver.go @@ -14,7 +14,7 @@ func PreparePatternMatching(patterns []string) (map[string]semver.Version, map[s for _, pattern := range patterns { p, err := semver.ParsePattern(pattern) if err != nil { - return nil, nil, fmt.Errorf("parse pattern: %s", err) + return nil, nil, fmt.Errorf("parse pattern: %w", err) } versions[pattern] = semver.Version{} diff --git a/pkg/notifier/notifier.go b/pkg/notifier/notifier.go index 429d4874..82b8b7f9 100644 --- a/pkg/notifier/notifier.go +++ b/pkg/notifier/notifier.go @@ -81,7 +81,7 @@ func (a App) Notify(ctx context.Context) error { } if err := a.sendNotification(ctx, "ketchup", ketchupsToNotify); err != nil { - return fmt.Errorf("send notification: %s", err) + return fmt.Errorf("send notification: %w", err) } if len(a.pushURL) != 0 { @@ -116,7 +116,7 @@ func (a App) updateRepositories(ctx context.Context, releases []model.Release) e for _, release := range releases { if release.Repository.ID != repo.ID { if err := a.repositoryService.Update(ctx, repo); err != nil { - return fmt.Errorf("update repository `%s`: %s", repo.Name, err) + return fmt.Errorf("update repository `%s`: %w", repo.Name, err) } repo = release.Repository @@ -126,7 +126,7 @@ func (a App) updateRepositories(ctx context.Context, releases []model.Release) e } if err := a.repositoryService.Update(ctx, repo); err != nil { - return fmt.Errorf("update repository `%s`: %s", repo.Name, err) + return fmt.Errorf("update repository `%s`: %w", repo.Name, err) } return nil @@ -270,7 +270,7 @@ func (a App) sendNotification(ctx context.Context, template string, ketchupToNot mr = mr.WithSubject(subject) if err := a.mailerApp.Send(ctx, mr); err != nil { - return fmt.Errorf("send email to %s: %s", ketchupUser.Email, err) + return fmt.Errorf("send email to %s: %w", ketchupUser.Email, err) } } @@ -281,12 +281,12 @@ func (a App) sendNotification(ctx context.Context, template string, ketchupToNot func (a App) Remind(ctx context.Context) error { usersToRemind, err := a.userService.ListReminderUsers(ctx) if err != nil { - return fmt.Errorf("get reminder users: %s", err) + return fmt.Errorf("get reminder users: %w", err) } remindKetchups, err := a.ketchupService.ListOutdated(ctx, usersToRemind...) if err != nil { - return fmt.Errorf("get daily ketchups to remind: %s", err) + return fmt.Errorf("get daily ketchups to remind: %w", err) } if len(remindKetchups) == 0 { @@ -297,7 +297,7 @@ func (a App) Remind(ctx context.Context) error { a.appendKetchupsToUser(ctx, usersToNotify, remindKetchups) if err := a.sendNotification(ctx, "ketchup_remind", usersToNotify); err != nil { - return fmt.Errorf("send remind notification: %s", err) + return fmt.Errorf("send remind notification: %w", err) } return nil diff --git a/pkg/notifier/releases.go b/pkg/notifier/releases.go index c3d728cc..045697b7 100644 --- a/pkg/notifier/releases.go +++ b/pkg/notifier/releases.go @@ -69,7 +69,7 @@ func (a App) getNewStandardReleases(ctx context.Context) ([]model.Release, uint6 for { repositories, _, err := a.repositoryService.ListByKinds(ctx, pageSize, last, model.Github, model.Docker, model.NPM, model.Pypi) if err != nil { - return nil, count, fmt.Errorf("fetch standard repositories: %s", err) + return nil, count, fmt.Errorf("fetch standard repositories: %w", err) } repoCount := len(repositories) @@ -126,7 +126,7 @@ func (a App) getNewHelmReleases(ctx context.Context) ([]model.Release, uint64, e for { repositories, _, err := a.repositoryService.ListByKinds(ctx, pageSize, last, model.Helm) if err != nil { - return nil, count, fmt.Errorf("fetch Helm repositories: %s", err) + return nil, count, fmt.Errorf("fetch Helm repositories: %w", err) } repoCount := len(repositories) diff --git a/pkg/provider/docker/docker.go b/pkg/provider/docker/docker.go index 26271f21..20c8e181 100644 --- a/pkg/provider/docker/docker.go +++ b/pkg/provider/docker/docker.go @@ -59,12 +59,12 @@ func New(config Config) App { func (a App) LatestVersions(ctx context.Context, repository string, patterns []string) (map[string]semver.Version, error) { versions, compiledPatterns, err := model.PreparePatternMatching(patterns) if err != nil { - return nil, fmt.Errorf("prepare pattern matching: %s", err) + return nil, fmt.Errorf("prepare pattern matching: %w", err) } registry, repository, auth, err := a.getImageDetails(ctx, repository) if err != nil { - return nil, fmt.Errorf("compute image details: %s", err) + return nil, fmt.Errorf("compute image details: %w", err) } tagsURL := fmt.Sprintf("%s/v2/%s/tags/list", registry, repository) @@ -78,7 +78,7 @@ func (a App) LatestVersions(ctx context.Context, repository string, patterns []s resp, err := req.Send(ctx, nil) if err != nil { - return nil, fmt.Errorf("fetch tags: %s", err) + return nil, fmt.Errorf("fetch tags: %w", err) } if err := browseRegistryTagsList(resp.Body, versions, compiledPatterns); err != nil { @@ -109,7 +109,7 @@ func (a App) getImageDetails(ctx context.Context, repository string) (string, st bearerToken, err := a.login(ctx, repository) if err != nil { - return "", "", "", fmt.Errorf("authenticate to docker hub: %s", err) + return "", "", "", fmt.Errorf("authenticate to docker hub: %w", err) } return registryURL, repository, fmt.Sprintf("Bearer %s", bearerToken), nil @@ -126,12 +126,12 @@ func (a App) login(ctx context.Context, repository string) (string, error) { resp, err := request.Post(authURL).Form(ctx, values) if err != nil { - return "", fmt.Errorf("authenticate to `%s`: %s", authURL, err) + return "", fmt.Errorf("authenticate to `%s`: %w", authURL, err) } var authContent authResponse if err := httpjson.Read(resp, &authContent); err != nil { - return "", fmt.Errorf("read auth token: %s", err) + return "", fmt.Errorf("read auth token: %w", err) } return authContent.AccessToken, nil @@ -155,7 +155,7 @@ func browseRegistryTagsList(body io.ReadCloser, versions map[string]semver.Versi }() if err := httpjson.Stream(body, versionsStream, "tags", true); err != nil { - return fmt.Errorf("read tags: %s", err) + return fmt.Errorf("read tags: %w", err) } <-done diff --git a/pkg/provider/github/github.go b/pkg/provider/github/github.go index 4200033c..7adfdb56 100644 --- a/pkg/provider/github/github.go +++ b/pkg/provider/github/github.go @@ -111,7 +111,7 @@ func (a app) Start(registerer prometheus.Registerer, done <-chan struct{}) { func (a app) LatestVersions(ctx context.Context, repository string, patterns []string) (map[string]semver.Version, error) { versions, compiledPatterns, err := model.PreparePatternMatching(patterns) if err != nil { - return nil, fmt.Errorf("prepare pattern matching: %s", err) + return nil, fmt.Errorf("prepare pattern matching: %w", err) } page := 1 @@ -119,12 +119,12 @@ func (a app) LatestVersions(ctx context.Context, repository string, patterns []s for { resp, err := req.Get(fmt.Sprintf("%s/repos/%s/tags?per_page=100&page=%d", apiURL, repository, page)).Send(ctx, nil) if err != nil { - return nil, fmt.Errorf("list page %d of tags: %s", page, err) + return nil, fmt.Errorf("list page %d of tags: %w", page, err) } var tags []Tag if err := httpjson.Read(resp, &tags); err != nil { - return nil, fmt.Errorf("read tags page #%d: %s", page, err) + return nil, fmt.Errorf("read tags page #%d: %w", page, err) } for _, tag := range tags { @@ -149,12 +149,12 @@ func (a app) LatestVersions(ctx context.Context, repository string, patterns []s func (a app) getRateLimit(ctx context.Context) (uint64, error) { resp, err := a.newClient().Get(fmt.Sprintf("%s/rate_limit", apiURL)).Send(ctx, nil) if err != nil { - return 0, fmt.Errorf("get rate limit: %s", err) + return 0, fmt.Errorf("get rate limit: %w", err) } var rateLimits RateLimitResponse if err := httpjson.Read(resp, &rateLimits); err != nil { - return 0, fmt.Errorf("read rate limit: %s", err) + return 0, fmt.Errorf("read rate limit: %w", err) } return rateLimits.Resources["core"].Remaining, nil diff --git a/pkg/provider/helm/helm.go b/pkg/provider/helm/helm.go index e97b6937..3801b9b9 100644 --- a/pkg/provider/helm/helm.go +++ b/pkg/provider/helm/helm.go @@ -47,7 +47,7 @@ func (a App) FetchIndex(ctx context.Context, url string, chartsPatterns map[stri var index charts if err := yaml.NewDecoder(resp.Body).Decode(&index); err != nil && err != io.EOF { - return nil, fmt.Errorf("parse yaml index: %s", err) + return nil, fmt.Errorf("parse yaml index: %w", err) } output := make(map[string]map[string]semver.Version, len(index.Entries)) @@ -59,7 +59,7 @@ func (a App) FetchIndex(ctx context.Context, url string, chartsPatterns map[stri versions, compiledPatterns, err := model.PreparePatternMatching(patterns) if err != nil { - return nil, fmt.Errorf("prepare pattern matching for `%s`: %s", key, err) + return nil, fmt.Errorf("prepare pattern matching for `%s`: %w", key, err) } for _, chart := range charts { diff --git a/pkg/provider/npm/npm.go b/pkg/provider/npm/npm.go index f5e95106..e1f84be4 100644 --- a/pkg/provider/npm/npm.go +++ b/pkg/provider/npm/npm.go @@ -34,17 +34,17 @@ func New() App { func (a App) LatestVersions(ctx context.Context, name string, patterns []string) (map[string]semver.Version, error) { versions, compiledPatterns, err := model.PreparePatternMatching(patterns) if err != nil { - return nil, fmt.Errorf("prepare pattern matching: %s", err) + return nil, fmt.Errorf("prepare pattern matching: %w", err) } resp, err := request.Get(fmt.Sprintf("%s/%s", registryURL, name)).Header("Accept", "application/vnd.npm.install-v1+json").Send(ctx, nil) if err != nil { - return nil, fmt.Errorf("fetch registry: %s", err) + return nil, fmt.Errorf("fetch registry: %w", err) } var content packageResp if err := httpjson.Read(resp, &content); err != nil { - return nil, fmt.Errorf("read versions: %s", err) + return nil, fmt.Errorf("read versions: %w", err) } for _, version := range content.Versions { diff --git a/pkg/provider/pypi/pypi.go b/pkg/provider/pypi/pypi.go index 0706b0e5..63bec9b6 100644 --- a/pkg/provider/pypi/pypi.go +++ b/pkg/provider/pypi/pypi.go @@ -30,17 +30,17 @@ func New() App { func (a App) LatestVersions(ctx context.Context, name string, patterns []string) (map[string]semver.Version, error) { versions, compiledPatterns, err := model.PreparePatternMatching(patterns) if err != nil { - return nil, fmt.Errorf("prepare pattern matching: %s", err) + return nil, fmt.Errorf("prepare pattern matching: %w", err) } resp, err := request.Get(fmt.Sprintf("%s/%s/json", registryURL, name)).Send(ctx, nil) if err != nil { - return nil, fmt.Errorf("fetch registry: %s", err) + return nil, fmt.Errorf("fetch registry: %w", err) } var content packageResp if err := httpjson.Read(resp, &content); err != nil { - return nil, fmt.Errorf("read versions: %s", err) + return nil, fmt.Errorf("read versions: %w", err) } for version := range content.Versions { diff --git a/pkg/semver/pattern.go b/pkg/semver/pattern.go index 36e79305..f239f5da 100644 --- a/pkg/semver/pattern.go +++ b/pkg/semver/pattern.go @@ -76,7 +76,7 @@ func ParsePattern(pattern string) (Pattern, error) { version, err := Parse(pattern[1:]) if err != nil { - return Pattern{}, fmt.Errorf("parse version in pattern: %s", err) + return Pattern{}, fmt.Errorf("parse version in pattern: %w", err) } constraintVersionSuffix := "" diff --git a/pkg/service/ketchup/ketchup.go b/pkg/service/ketchup/ketchup.go index 824db55a..4cba7218 100644 --- a/pkg/service/ketchup/ketchup.go +++ b/pkg/service/ketchup/ketchup.go @@ -30,7 +30,7 @@ func New(ketchupStore model.KetchupStore, repositoryService model.RepositoryServ func (a App) List(ctx context.Context, pageSize uint, last string) ([]model.Ketchup, uint64, error) { list, total, err := a.ketchupStore.List(ctx, pageSize, last) if err != nil { - return nil, 0, httpModel.WrapInternal(fmt.Errorf("list: %s", err)) + return nil, 0, httpModel.WrapInternal(fmt.Errorf("list: %w", err)) } enrichedList := enrichKetchupsWithSemver(list) @@ -48,7 +48,7 @@ func (a App) ListForRepositories(ctx context.Context, repositories []model.Repos list, err := a.ketchupStore.ListByRepositoriesIDAndFrequencies(ctx, ids, frequencies...) if err != nil { - return nil, httpModel.WrapInternal(fmt.Errorf("list by ids: %s", err)) + return nil, httpModel.WrapInternal(fmt.Errorf("list by ids: %w", err)) } return enrichKetchupsWithSemver(list), nil @@ -63,7 +63,7 @@ func (a App) ListOutdated(ctx context.Context, users ...model.User) ([]model.Ket list, err := a.ketchupStore.ListOutdated(ctx, usersIds...) if err != nil { - return nil, httpModel.WrapInternal(fmt.Errorf("list outdated by frequency: %s", err)) + return nil, httpModel.WrapInternal(fmt.Errorf("list outdated by frequency: %w", err)) } return list, nil @@ -86,7 +86,7 @@ func (a App) Create(ctx context.Context, item model.Ketchup) (model.Ketchup, err } if _, err := a.ketchupStore.Create(ctx, item); err != nil { - return httpModel.WrapInternal(fmt.Errorf("create: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("create: %w", err)) } output = item @@ -102,7 +102,7 @@ func (a App) UpdateAll(ctx context.Context) error { return a.ketchupStore.UpdateAll(ctx) }) if err != nil { - return fmt.Errorf("update all ketchup: %s", err) + return fmt.Errorf("update all ketchup: %w", err) } return nil @@ -115,7 +115,7 @@ func (a App) Update(ctx context.Context, oldPattern string, item model.Ketchup) err := a.ketchupStore.DoAtomic(ctx, func(ctx context.Context) error { old, err := a.ketchupStore.GetByRepository(ctx, item.Repository.ID, oldPattern, true) if err != nil { - return httpModel.WrapInternal(fmt.Errorf("fetch: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("fetch: %w", err)) } if old.Repository.IsZero() { @@ -138,14 +138,14 @@ func (a App) Update(ctx context.Context, oldPattern string, item model.Ketchup) if old.Pattern != item.Pattern { repo, err := a.repositoryService.GetOrCreate(ctx, old.Repository.Kind, old.Repository.Name, old.Repository.Part, item.Pattern) if err != nil { - return httpModel.WrapInternal(fmt.Errorf("get repository version: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("get repository version: %w", err)) } current.Repository = repo } if err := a.ketchupStore.Update(ctx, current, old.Pattern); err != nil { - return httpModel.WrapInternal(fmt.Errorf("update: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("update: %w", err)) } output = current @@ -175,7 +175,7 @@ func (a App) Delete(ctx context.Context, item model.Ketchup) (err error) { return a.ketchupStore.DoAtomic(ctx, func(ctx context.Context) error { old, err := a.ketchupStore.GetByRepository(ctx, item.Repository.ID, item.Pattern, true) if err != nil { - return httpModel.WrapInternal(fmt.Errorf("fetch current: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("fetch current: %w", err)) } if old.Repository.IsZero() { @@ -187,7 +187,7 @@ func (a App) Delete(ctx context.Context, item model.Ketchup) (err error) { } if err = a.ketchupStore.Delete(ctx, old); err != nil { - return httpModel.WrapInternal(fmt.Errorf("delete: %s", err)) + return httpModel.WrapInternal(fmt.Errorf("delete: %w", err)) } return nil @@ -208,7 +208,7 @@ func (a App) check(ctx context.Context, old, new model.Ketchup) error { if len(strings.TrimSpace(new.Pattern)) == 0 { output = append(output, errors.New("pattern is required")) } else if _, err := semver.ParsePattern(new.Pattern); err != nil { - output = append(output, fmt.Errorf("pattern is invalid: %s", err)) + output = append(output, fmt.Errorf("pattern is invalid: %w", err)) } if len(strings.TrimSpace(new.Version)) == 0 { diff --git a/pkg/store/repository/repository.go b/pkg/store/repository/repository.go index 0e196294..fe414f05 100644 --- a/pkg/store/repository/repository.go +++ b/pkg/store/repository/repository.go @@ -110,7 +110,7 @@ func (a App) List(ctx context.Context, pageSize uint, last string) ([]model.Repo if len(last) != 0 { lastID, err := strconv.ParseUint(last, 10, 64) if err != nil { - return nil, 0, fmt.Errorf("invalid last key: %s", err) + return nil, 0, fmt.Errorf("invalid last key: %w", err) } queryArgs = append(queryArgs, lastID)