Skip to content

Commit

Permalink
[Disk Manager] internal/pkg/tasks should not depend on internal/pkg/e…
Browse files Browse the repository at this point in the history
…rrors (#104)
  • Loading branch information
SvartMetal authored Jan 10, 2024
1 parent e31e7a3 commit 0ce445f
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 163 deletions.
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/auth/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"hash/crc32"

auth_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/pkg/auth"
metadata "github.com/ydb-platform/ydb-go-yc-metadata"
"github.com/ydb-platform/ydb-go-yc-metadata/trace"
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/ydb-platform/nbs/cloud/disk_manager/api/yandex/cloud/priv/disk_manager/v1"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/api"
client_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/configs/client/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
sdk_client "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client"
sdk_client_config "github.com/ydb-platform/nbs/cloud/disk_manager/pkg/client/config"
"google.golang.org/grpc"
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/clients/nbs/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth"
nbs_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
coreprotos "github.com/ydb-platform/nbs/cloud/storage/core/protos"
"golang.org/x/exp/maps"
"google.golang.org/grpc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/ydb-platform/nbs/cloud/blockstore/public/api/protos"
nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/clients/nbs/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/ydb-platform/nbs/cloud/blockstore/public/api/protos"
nbs_client "github.com/ydb-platform/nbs/cloud/blockstore/public/sdk/go/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/common"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/clients/nfs/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/auth"
nfs_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nfs/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/common"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
nfs_client "github.com/ydb-platform/nbs/cloud/filestore/public/sdk/go/client"
"golang.org/x/exp/maps"
)
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/dataplane/nbs/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nbs

import (
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
zstdcgo "github.com/DataDog/zstd"
"github.com/pierrec/lz4"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/dataplane/snapshot/storage/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
"github.com/ydb-platform/nbs/library/go/blockcodecs"
_ "github.com/ydb-platform/nbs/library/go/blockcodecs/all"
)
Expand Down
130 changes: 0 additions & 130 deletions cloud/disk_manager/internal/pkg/errors/errors.go

This file was deleted.

7 changes: 0 additions & 7 deletions cloud/disk_manager/internal/pkg/errors/ya.make

This file was deleted.

2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/persistence/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
aws_credentials "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
aws_s3 "github.com/aws/aws-sdk-go/service/s3"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
persistence_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/persistence/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/persistence/s3_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"time"

"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/persistence/ydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"strings"
"time"

"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
persistence_config "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/persistence/config"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
"github.com/ydb-platform/ydb-go-sdk/v3"
ydb_credentials "github.com/ydb-platform/ydb-go-sdk/v3/credentials"
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
Expand Down
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/persistence/ydb_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strings"
"time"

"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/logging"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/monitoring/metrics"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/errors"
"github.com/ydb-platform/ydb-go-sdk/v3"
ydb_metrics "github.com/ydb-platform/ydb-go-sdk/v3/metrics"
ydb_trace "github.com/ydb-platform/ydb-go-sdk/v3/trace"
Expand Down
81 changes: 68 additions & 13 deletions cloud/disk_manager/internal/pkg/tasks/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,115 @@
package errors

import (
"errors"
"fmt"
"runtime/debug"

"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/errors"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/tasks/common/protos"
grpc_status "google.golang.org/grpc/status"
)

////////////////////////////////////////////////////////////////////////////////

type RetriableError = errors.RetriableError
type RetriableError struct {
Err error
IgnoreRetryLimit bool
}

func NewRetriableError(err error) *RetriableError {
return errors.NewRetriableError(err)
return &RetriableError{
Err: err,
}
}

func NewRetriableErrorf(format string, a ...any) *RetriableError {
return errors.NewRetriableErrorf(format, a...)
return NewRetriableError(fmt.Errorf(format, a...))
}

func NewRetriableErrorWithIgnoreRetryLimit(err error) *RetriableError {
return errors.NewRetriableErrorWithIgnoreRetryLimit(err)
return &RetriableError{
Err: err,
IgnoreRetryLimit: true,
}
}

func NewRetriableErrorWithIgnoreRetryLimitf(format string, a ...any) *RetriableError {
return errors.NewRetriableErrorWithIgnoreRetryLimitf(format, a...)
return NewRetriableErrorWithIgnoreRetryLimit(fmt.Errorf(format, a...))
}

func NewEmptyRetriableError() *RetriableError {
return errors.NewEmptyRetriableError()
return &RetriableError{}
}

func (e *RetriableError) Error() string {
return fmt.Sprintf("Retriable error, IgnoreRetryLimit=%v: %v", e.IgnoreRetryLimit, e.Err)
}

func (e *RetriableError) Unwrap() error {
return e.Err
}

func (e *RetriableError) Is(target error) bool {
t, ok := target.(*RetriableError)
if !ok {
return false
}

return t.Err == nil || (e.Err == t.Err)
}

////////////////////////////////////////////////////////////////////////////////

type NonRetriableError = errors.NonRetriableError
type NonRetriableError struct {
Err error
Silent bool
stackTrace []byte
}

func NewNonRetriableError(err error) *NonRetriableError {
return errors.NewNonRetriableError(err)
return newNonRetriableError(err, false)
}

func NewNonRetriableErrorf(format string, a ...any) *NonRetriableError {
return errors.NewNonRetriableErrorf(format, a...)
return newNonRetriableError(fmt.Errorf(format, a...), false)
}

func NewSilentNonRetriableError(err error) *NonRetriableError {
return errors.NewSilentNonRetriableError(err)
return newNonRetriableError(err, true)
}

func NewSilentNonRetriableErrorf(format string, a ...any) *NonRetriableError {
return errors.NewSilentNonRetriableErrorf(format, a...)
return newNonRetriableError(fmt.Errorf(format, a...), true)
}

func NewEmptyNonRetriableError() *NonRetriableError {
return errors.NewEmptyNonRetriableError()
return newNonRetriableError(nil, false)
}

func newNonRetriableError(err error, silent bool) *NonRetriableError {
return &NonRetriableError{
Err: err,
Silent: silent,
stackTrace: debug.Stack(),
}
}

func (e *NonRetriableError) Error() string {
msg := fmt.Sprintf("Non retriable error, Silent=%v: %v", e.Silent, e.Err)
return appendStackTrace(msg, e.stackTrace)
}

func (e *NonRetriableError) Unwrap() error {
return e.Err
}

func (e *NonRetriableError) Is(target error) bool {
t, ok := target.(*NonRetriableError)
if !ok {
return false
}

return t.Err == nil || (e.Err == t.Err)
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 0ce445f

Please sign in to comment.