Skip to content

Commit

Permalink
Add err113 check (#206)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.dev>
  • Loading branch information
teran committed Sep 2, 2024
1 parent 8106166 commit 3132dea
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
- decorder
- dogsled
- durationcheck
- err113
- errname
- godox
- gofmt
Expand Down
5 changes: 3 additions & 2 deletions manager/presenter/grpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpc
import (
"context"

"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -186,7 +187,7 @@ func (h *handlers) CreateObject(ctx context.Context, in *v1.CreateObjectRequest)
func (h *handlers) ListObjects(ctx context.Context, in *v1.ListObjectsRequest) (*v1.ListObjectsResponse, error) {
objects, err := h.svc.ListObjects(ctx, in.GetNamespace(), in.GetContainer(), in.GetVersion())
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
return nil, mapServiceError(err)
Expand All @@ -200,7 +201,7 @@ func (h *handlers) ListObjects(ctx context.Context, in *v1.ListObjectsRequest) (
func (h *handlers) GetObjectURL(ctx context.Context, in *v1.GetObjectURLRequest) (*v1.GetObjectURLResponse, error) {
url, err := h.svc.GetObjectURL(ctx, in.GetNamespace(), in.GetContainer(), in.GetVersion(), in.GetKey())
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
return nil, mapServiceError(err)
Expand Down
9 changes: 5 additions & 4 deletions publisher/presenter/html/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

sprig "github.com/Masterminds/sprig/v3"
echo "github.com/labstack/echo/v4"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/teran/archived/models"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (h *handlers) ContainerIndex(c echo.Context) error {

pagesCount, containers, err := h.svc.ListContainersByPage(c.Request().Context(), namespace, page)
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return c.Render(http.StatusNotFound, notFoundTemplateFilename, nil)
}
return err
Expand Down Expand Up @@ -119,7 +120,7 @@ func (h *handlers) VersionIndex(c echo.Context) error {

pagesCount, versions, err := h.svc.ListPublishedVersionsByPage(c.Request().Context(), namespace, container, page)
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return c.Render(http.StatusNotFound, notFoundTemplateFilename, nil)
}
return err
Expand Down Expand Up @@ -163,7 +164,7 @@ func (h *handlers) ObjectIndex(c echo.Context) error {

pagesCount, objects, err := h.svc.ListObjectsByPage(c.Request().Context(), namespace, container, version, page)
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return c.Render(http.StatusNotFound, notFoundTemplateFilename, nil)
}
return err
Expand Down Expand Up @@ -202,7 +203,7 @@ func (h *handlers) GetObject(c echo.Context) error {

link, err := h.svc.GetObjectURL(c.Request().Context(), namespace, container, version, key)
if err != nil {
if err == service.ErrNotFound {
if errors.Is(err, service.ErrNotFound) {
return c.Render(http.StatusNotFound, notFoundTemplateFilename, nil)
}
return err
Expand Down
19 changes: 10 additions & 9 deletions repositories/cache/metadata/memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

memcacheCli "github.com/bradfitz/gomemcache/memcache"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

emodels "github.com/teran/archived/exporter/models"
Expand Down Expand Up @@ -53,7 +54,7 @@ func (m *memcache) ListNamespaces(ctx context.Context) ([]string, error) {

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -106,7 +107,7 @@ func (m *memcache) ListContainers(ctx context.Context, namespace string) ([]mode

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -154,7 +155,7 @@ func (m *memcache) ListContainersByPage(ctx context.Context, namespace string, o

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -204,7 +205,7 @@ func (m *memcache) GetLatestPublishedVersionByContainer(ctx context.Context, nam

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -246,7 +247,7 @@ func (m *memcache) ListAllVersionsByContainer(ctx context.Context, namespace, co

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -288,7 +289,7 @@ func (m *memcache) ListPublishedVersionsByContainer(ctx context.Context, namespa

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -337,7 +338,7 @@ func (m *memcache) ListPublishedVersionsByContainerAndPage(ctx context.Context,

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -403,7 +404,7 @@ func (m *memcache) ListObjects(ctx context.Context, namespace, container, versio

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down Expand Up @@ -459,7 +460,7 @@ func (m *memcache) GetBlobKeyByObject(ctx context.Context, namespace, container,

item, err := m.cli.Get(cacheKey)
if err != nil {
if err == memcacheCli.ErrCacheMiss {
if errors.Is(err, memcacheCli.ErrCacheMiss) {
log.WithFields(log.Fields{
"key": cacheKey,
}).Tracef("cache miss")
Expand Down
4 changes: 2 additions & 2 deletions repositories/metadata/postgresql/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func migrateUpWithMigrationsPath(dsn, migrationsPath string) error {
return err
}

if err = m.Up(); err != nil && err != migrate.ErrNoChange {
if err = m.Up(); err != nil && !errors.Is(err, migrate.ErrNoChange) {
return errors.Wrap(err, "error migrating database")
}

Expand All @@ -68,7 +68,7 @@ func migrateDownWithMigrationsPath(dsn, migrationsPath string) error {
return err
}

if err = m.Down(); err != nil && err != migrate.ErrNoChange {
if err = m.Down(); err != nil && !errors.Is(err, migrate.ErrNoChange) {
return errors.Wrap(err, "error migrating database")
}

Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *service) EnsureBLOBPresenceOrGetUploadURL(ctx context.Context, checksum
return "", nil
}

if err == metadata.ErrNotFound {
if errors.Is(err, metadata.ErrNotFound) {
url, err := s.blobRepo.PutBlobURL(ctx, checksum)
if err != nil {
return "", err
Expand Down

0 comments on commit 3132dea

Please sign in to comment.