From de162c55334d6117e9ece015a2fb94dec05c56d4 Mon Sep 17 00:00:00 2001 From: Michael Gaffney Date: Tue, 25 Aug 2020 12:18:14 -0400 Subject: [PATCH] Replace and remove ErrNilParameter with ErrInvalidParameter (#295) --- internal/auth/password/argon2.go | 2 +- internal/auth/password/argon2_test.go | 2 +- internal/auth/password/repository.go | 6 +-- internal/auth/password/repository_account.go | 14 +++--- .../auth/password/repository_account_test.go | 8 +-- .../auth/password/repository_authmethod.go | 8 +-- .../password/repository_authmethod_test.go | 4 +- .../auth/password/repository_configuration.go | 2 +- .../password/repository_configuration_test.go | 2 +- internal/auth/password/repository_password.go | 6 +-- internal/auth/password/repository_test.go | 8 +-- internal/authtoken/repository.go | 8 +-- internal/authtoken/repository_test.go | 8 +-- internal/db/common/update.go | 10 ++-- internal/db/error.go | 3 -- internal/db/read_writer.go | 50 +++++++++---------- internal/db/read_writer_test.go | 50 +++++++++---------- internal/host/static/repository.go | 6 +-- internal/host/static/repository_host.go | 12 ++--- .../host/static/repository_host_catalog.go | 12 ++--- .../static/repository_host_catalog_test.go | 8 +-- internal/host/static/repository_host_set.go | 14 +++--- .../host/static/repository_host_set_test.go | 8 +-- internal/host/static/repository_host_test.go | 8 +-- internal/host/static/repository_test.go | 8 +-- internal/iam/repository_group.go | 12 ++--- internal/iam/repository_group_test.go | 10 ++-- internal/iam/repository_principal_role.go | 2 +- .../iam/repository_principal_role_test.go | 2 +- internal/iam/repository_role.go | 12 ++--- internal/iam/repository_role_grant.go | 2 +- internal/iam/repository_role_test.go | 10 ++-- internal/iam/repository_scope.go | 10 ++-- internal/iam/repository_scope_test.go | 2 +- internal/iam/repository_user.go | 8 +-- internal/iam/repository_user_test.go | 2 +- internal/iam/role_grant.go | 6 +-- internal/iam/role_grant_test.go | 4 +- internal/iam/user.go | 2 +- internal/kms/common/root_test.go | 2 +- internal/kms/repository_root_key.go | 6 +-- internal/kms/repository_root_key_test.go | 2 +- internal/kms/repository_root_key_version.go | 12 ++--- .../kms/repository_root_key_version_test.go | 4 +- 44 files changed, 187 insertions(+), 190 deletions(-) diff --git a/internal/auth/password/argon2.go b/internal/auth/password/argon2.go index 0f3a8d15c..3ea038b22 100644 --- a/internal/auth/password/argon2.go +++ b/internal/auth/password/argon2.go @@ -123,7 +123,7 @@ func newArgon2Credential(accountId string, password string, conf *Argon2Configur return nil, fmt.Errorf("new: password argon2 credential: no password: %w", db.ErrInvalidParameter) } if conf == nil { - return nil, fmt.Errorf("new: password argon2 credential: no argon2 configuration: %w", db.ErrNilParameter) + return nil, fmt.Errorf("new: password argon2 credential: no argon2 configuration: %w", db.ErrInvalidParameter) } id, err := newArgon2CredentialId() diff --git a/internal/auth/password/argon2_test.go b/internal/auth/password/argon2_test.go index 3fe434cbe..ce263e68a 100644 --- a/internal/auth/password/argon2_test.go +++ b/internal/auth/password/argon2_test.go @@ -349,7 +349,7 @@ func TestArgon2Credential_New(t *testing.T) { conf: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "valid-password", diff --git a/internal/auth/password/repository.go b/internal/auth/password/repository.go index 041222cd1..8f02295cb 100644 --- a/internal/auth/password/repository.go +++ b/internal/auth/password/repository.go @@ -25,11 +25,11 @@ type Repository struct { func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) { switch { case r == nil: - return nil, fmt.Errorf("db.Reader: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Reader: %w", db.ErrInvalidParameter) case w == nil: - return nil, fmt.Errorf("db.Writer: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Writer: %w", db.ErrInvalidParameter) case kms == nil: - return nil, fmt.Errorf("kms: %w", db.ErrNilParameter) + return nil, fmt.Errorf("kms: %w", db.ErrInvalidParameter) } opts := getOpts(opt...) diff --git a/internal/auth/password/repository_account.go b/internal/auth/password/repository_account.go index 16eafc0d6..918de170a 100644 --- a/internal/auth/password/repository_account.go +++ b/internal/auth/password/repository_account.go @@ -27,10 +27,10 @@ import ( // unique within a.AuthMethodId. func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Account, opt ...Option) (*Account, error) { if a == nil { - return nil, fmt.Errorf("create: password account: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: password account: %w", db.ErrInvalidParameter) } if a.Account == nil { - return nil, fmt.Errorf("create: password account: embedded Account: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: password account: embedded Account: %w", db.ErrInvalidParameter) } if a.AuthMethodId == "" { return nil, fmt.Errorf("create: password account: no auth method id: %w", db.ErrInvalidParameter) @@ -39,7 +39,7 @@ func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Accou return nil, fmt.Errorf("create: password account: public id not empty: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("create: password account: scope id empty: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: password account: scope id empty: %w", db.ErrInvalidParameter) } if !validLoginName(a.LoginName) { return nil, fmt.Errorf("create: password account: invalid user name: %w", db.ErrInvalidParameter) @@ -157,7 +157,7 @@ func (r *Repository) DeleteAccount(ctx context.Context, scopeId, withPublicId st return db.NoRowsAffected, fmt.Errorf("delete: password account: missing public id: %w", db.ErrInvalidParameter) } if scopeId == "" { - return db.NoRowsAffected, fmt.Errorf("delete: password account: scope id empty: %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete: password account: scope id empty: %w", db.ErrInvalidParameter) } ac := allocAccount() ac.PublicId = withPublicId @@ -214,10 +214,10 @@ func validLoginName(u string) bool { // cannot be set to NULL. func (r *Repository) UpdateAccount(ctx context.Context, scopeId string, a *Account, version uint32, fieldMaskPaths []string, opt ...Option) (*Account, int, error) { if a == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: password account: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: password account: %w", db.ErrInvalidParameter) } if a.Account == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: password account: embedded Account: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: password account: embedded Account: %w", db.ErrInvalidParameter) } if a.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: password account: missing public id: %w", db.ErrInvalidParameter) @@ -226,7 +226,7 @@ func (r *Repository) UpdateAccount(ctx context.Context, scopeId string, a *Accou return nil, db.NoRowsAffected, fmt.Errorf("update: password account: no version supplied: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update: password account: scope id empty: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: password account: scope id empty: %w", db.ErrInvalidParameter) } var changeLoginName bool diff --git a/internal/auth/password/repository_account_test.go b/internal/auth/password/repository_account_test.go index 2faef0777..3926795d3 100644 --- a/internal/auth/password/repository_account_test.go +++ b/internal/auth/password/repository_account_test.go @@ -57,12 +57,12 @@ func TestRepository_CreateAccount(t *testing.T) { }{ { name: "nil-Account", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-Account", in: &Account{}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "invalid-no-scope-id", @@ -633,7 +633,7 @@ func TestRepository_UpdateAccount(t *testing.T) { }, chgFn: makeNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-Account", @@ -642,7 +642,7 @@ func TestRepository_UpdateAccount(t *testing.T) { }, chgFn: makeEmbeddedNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "no-public-id", diff --git a/internal/auth/password/repository_authmethod.go b/internal/auth/password/repository_authmethod.go index ac2bf95db..fa597b5c3 100644 --- a/internal/auth/password/repository_authmethod.go +++ b/internal/auth/password/repository_authmethod.go @@ -24,10 +24,10 @@ import ( // unique within m.ScopeId. func (r *Repository) CreateAuthMethod(ctx context.Context, m *AuthMethod, opt ...Option) (*AuthMethod, error) { if m == nil { - return nil, fmt.Errorf("create: password auth method: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: password auth method: %w", db.ErrInvalidParameter) } if m.AuthMethod == nil { - return nil, fmt.Errorf("create: password auth method: embedded AuthMethod: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: password auth method: embedded AuthMethod: %w", db.ErrInvalidParameter) } if m.ScopeId == "" { return nil, fmt.Errorf("create: password auth method: no scope id: %w", db.ErrInvalidParameter) @@ -182,13 +182,13 @@ func (r *Repository) DeleteAuthMethod(ctx context.Context, scopeId, publicId str // are included in the fieldMaskPaths, then an error is returned. func (r *Repository) UpdateAuthMethod(ctx context.Context, authMethod *AuthMethod, version uint32, fieldMaskPaths []string, opt ...Option) (*AuthMethod, int, error) { if authMethod == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod: %w", db.ErrInvalidParameter) } if authMethod.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod public id: %w", db.ErrInvalidParameter) } if authMethod.ScopeId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: scope id empty: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: scope id empty: %w", db.ErrInvalidParameter) } for _, f := range fieldMaskPaths { switch { diff --git a/internal/auth/password/repository_authmethod_test.go b/internal/auth/password/repository_authmethod_test.go index a7648c5eb..4b679cb8b 100644 --- a/internal/auth/password/repository_authmethod_test.go +++ b/internal/auth/password/repository_authmethod_test.go @@ -37,12 +37,12 @@ func TestRepository_CreateAuthMethod(t *testing.T) { }{ { name: "nil-AuthMethod", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-AuthMethod", in: &AuthMethod{}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "invalid-no-scope-id", diff --git a/internal/auth/password/repository_configuration.go b/internal/auth/password/repository_configuration.go index 6ffe37722..99e283b3a 100644 --- a/internal/auth/password/repository_configuration.go +++ b/internal/auth/password/repository_configuration.go @@ -42,7 +42,7 @@ func (r *Repository) GetConfiguration(ctx context.Context, authMethodId string) // updates AuthMethod to use the previous configuration. func (r *Repository) SetConfiguration(ctx context.Context, scopeId string, c Configuration) (Configuration, error) { if c == nil { - return nil, fmt.Errorf("set password configuration: %w", db.ErrNilParameter) + return nil, fmt.Errorf("set password configuration: %w", db.ErrInvalidParameter) } if c.AuthMethodId() == "" { return nil, fmt.Errorf("set password configuration: no auth method id: %w", db.ErrInvalidParameter) diff --git a/internal/auth/password/repository_configuration_test.go b/internal/auth/password/repository_configuration_test.go index 28d8f907a..0f7b4f53f 100644 --- a/internal/auth/password/repository_configuration_test.go +++ b/internal/auth/password/repository_configuration_test.go @@ -216,7 +216,7 @@ func TestRepository_SetConfiguration(t *testing.T) { }{ { name: "invalid-nil-config", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-config", diff --git a/internal/auth/password/repository_password.go b/internal/auth/password/repository_password.go index 219284b72..6dad3f183 100644 --- a/internal/auth/password/repository_password.go +++ b/internal/auth/password/repository_password.go @@ -41,7 +41,7 @@ func (r *Repository) Authenticate(ctx context.Context, scopeId, authMethodId, lo return nil, fmt.Errorf("password authenticate: no password: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("password authenticate: no scopeId: %w", db.ErrNilParameter) + return nil, fmt.Errorf("password authenticate: no scopeId: %w", db.ErrInvalidParameter) } databaseWrapper, err := r.kms.GetWrapper(ctx, scopeId, kms.KeyPurposeDatabase) @@ -120,7 +120,7 @@ func (r *Repository) ChangePassword(ctx context.Context, scopeId, accountId, old return nil, fmt.Errorf("change password: no version supplied: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("change password: no scopeId: %w", db.ErrNilParameter) + return nil, fmt.Errorf("change password: no scopeId: %w", db.ErrInvalidParameter) } authAccount, err := r.LookupAccount(ctx, accountId) @@ -258,7 +258,7 @@ func (r *Repository) SetPassword(ctx context.Context, scopeId, accountId, passwo return nil, fmt.Errorf("set password: no version supplied: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("set password: no scopeId: %w", db.ErrNilParameter) + return nil, fmt.Errorf("set password: no scopeId: %w", db.ErrInvalidParameter) } oplogWrapper, err := r.kms.GetWrapper(ctx, scopeId, kms.KeyPurposeOplog) diff --git a/internal/auth/password/repository_test.go b/internal/auth/password/repository_test.go index 258f15bae..bf4482c34 100644 --- a/internal/auth/password/repository_test.go +++ b/internal/auth/password/repository_test.go @@ -67,7 +67,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-writer", @@ -77,7 +77,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-wrapper", @@ -87,7 +87,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "all-nils", @@ -97,7 +97,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, } for _, tt := range tests { diff --git a/internal/authtoken/repository.go b/internal/authtoken/repository.go index 181e15d8a..bd6ce0fbb 100644 --- a/internal/authtoken/repository.go +++ b/internal/authtoken/repository.go @@ -37,11 +37,11 @@ type Repository struct { func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) { switch { case r == nil: - return nil, fmt.Errorf("db.Reader: auth token: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Reader: auth token: %w", db.ErrInvalidParameter) case w == nil: - return nil, fmt.Errorf("db.Writer: auth token: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Writer: auth token: %w", db.ErrInvalidParameter) case kms == nil: - return nil, fmt.Errorf("kms: auth token: %w", db.ErrNilParameter) + return nil, fmt.Errorf("kms: auth token: %w", db.ErrInvalidParameter) } opts := getOpts(opt...) @@ -62,7 +62,7 @@ func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repo // or an error will be returned. All options are ignored. func (r *Repository) CreateAuthToken(ctx context.Context, withIamUser *iam.User, withAuthAccountId string, opt ...Option) (*AuthToken, error) { if withIamUser == nil { - return nil, fmt.Errorf("create: auth token: no user: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: auth token: no user: %w", db.ErrInvalidParameter) } if withIamUser.GetPublicId() == "" { return nil, fmt.Errorf("create: auth token: no user id: %w", db.ErrInvalidParameter) diff --git a/internal/authtoken/repository_test.go b/internal/authtoken/repository_test.go index 6863e198a..90d734db9 100644 --- a/internal/authtoken/repository_test.go +++ b/internal/authtoken/repository_test.go @@ -77,7 +77,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-writer", @@ -87,7 +87,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-kms", @@ -97,7 +97,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "all-nils", @@ -107,7 +107,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, } for _, tt := range tests { diff --git a/internal/db/common/update.go b/internal/db/common/update.go index ed5e27daa..9aeb45148 100644 --- a/internal/db/common/update.go +++ b/internal/db/common/update.go @@ -13,8 +13,8 @@ import ( ) var ( - // ErrNilParameter is returned when a required parameter is nil. - ErrNilParameter = errors.New("nil parameter") + // ErrInvalidParameter is returned when a required parameter is nil. + ErrInvalidParameter = errors.New("nil parameter") ) // UpdateFields will create a map[string]interface of the update values to be @@ -23,7 +23,7 @@ var ( // intersect. fieldMaskPaths and setToNullPaths cannot both be zero len. func UpdateFields(i interface{}, fieldMaskPaths []string, setToNullPaths []string) (map[string]interface{}, error) { if i == nil { - return nil, fmt.Errorf("interface is missing: %w", ErrNilParameter) + return nil, fmt.Errorf("interface is missing: %w", ErrInvalidParameter) } if fieldMaskPaths == nil { fieldMaskPaths = []string{} @@ -117,10 +117,10 @@ func findMissingPaths(paths []string, foundPaths map[string]struct{}) []string { // original func Intersection(av, bv []string) ([]string, map[string]string, map[string]string, error) { if av == nil { - return nil, nil, nil, fmt.Errorf("av is missing: %w", ErrNilParameter) + return nil, nil, nil, fmt.Errorf("av is missing: %w", ErrInvalidParameter) } if bv == nil { - return nil, nil, nil, fmt.Errorf("bv is missing: %w", ErrNilParameter) + return nil, nil, nil, fmt.Errorf("bv is missing: %w", ErrInvalidParameter) } if len(av) == 0 && len(bv) == 0 { return []string{}, map[string]string{}, map[string]string{}, nil diff --git a/internal/db/error.go b/internal/db/error.go index e6f0f78fb..1d9f62177 100644 --- a/internal/db/error.go +++ b/internal/db/error.go @@ -28,9 +28,6 @@ var ( // to the repository resulted in a unique constraint violation. ErrNotUnique = errors.New("unique constraint violation") - // ErrNilParameter is returned when a required parameter is nil. - ErrNilParameter = errors.New("nil parameter") - // ErrRecordNotFound returns a "record not found" error and it only occurs // when attempting to read from the database into struct. // When reading into a slice it won't return this error. diff --git a/internal/db/read_writer.go b/internal/db/read_writer.go index 9dea47d9b..4be4584d0 100644 --- a/internal/db/read_writer.go +++ b/internal/db/read_writer.go @@ -182,7 +182,7 @@ func New(underlying *gorm.DB) *Db { // DB returns the sql.DB func (rw *Db) DB() (*sql.DB, error) { if rw.underlying == nil { - return nil, fmt.Errorf("missing underlying db: %w", ErrNilParameter) + return nil, fmt.Errorf("missing underlying db: %w", ErrInvalidParameter) } return rw.underlying.DB(), nil } @@ -190,10 +190,10 @@ func (rw *Db) DB() (*sql.DB, error) { // Scan rows will scan the rows into the interface func (rw *Db) ScanRows(rows *sql.Rows, result interface{}) error { if rw.underlying == nil { - return fmt.Errorf("scan rows: missing underlying db %w", ErrNilParameter) + return fmt.Errorf("scan rows: missing underlying db %w", ErrInvalidParameter) } if isNil(result) { - return fmt.Errorf("scan rows: result is missing %w", ErrNilParameter) + return fmt.Errorf("scan rows: result is missing %w", ErrInvalidParameter) } return rw.underlying.ScanRows(rows, result) } @@ -217,10 +217,10 @@ func (rw *Db) lookupAfterWrite(ctx context.Context, i interface{}, opt ...Option // cannot be used together. WithLookup with to force a lookup after create. func (rw *Db) Create(ctx context.Context, i interface{}, opt ...Option) error { if rw.underlying == nil { - return fmt.Errorf("create: missing underlying db: %w", ErrNilParameter) + return fmt.Errorf("create: missing underlying db: %w", ErrInvalidParameter) } if isNil(i) { - return fmt.Errorf("create: interface is missing: %w", ErrNilParameter) + return fmt.Errorf("create: interface is missing: %w", ErrInvalidParameter) } opts := GetOpts(opt...) withOplog := opts.withOplog @@ -279,7 +279,7 @@ func (rw *Db) Create(ctx context.Context, i interface{}, opt ...Option) error { // together. WithLookup is not a supported option. func (rw *Db) CreateItems(ctx context.Context, createItems []interface{}, opt ...Option) error { if rw.underlying == nil { - return fmt.Errorf("create items: missing underlying db: %w", ErrNilParameter) + return fmt.Errorf("create items: missing underlying db: %w", ErrInvalidParameter) } if len(createItems) == 0 { return fmt.Errorf("create items: no interfaces to create: %w", ErrInvalidParameter) @@ -358,10 +358,10 @@ func (rw *Db) CreateItems(ctx context.Context, createItems []interface{}, opt .. // WithVersion option and will return an error. func (rw *Db) Update(ctx context.Context, i interface{}, fieldMaskPaths []string, setToNullPaths []string, opt ...Option) (int, error) { if rw.underlying == nil { - return NoRowsAffected, fmt.Errorf("update: missing underlying db %w", ErrNilParameter) + return NoRowsAffected, fmt.Errorf("update: missing underlying db %w", ErrInvalidParameter) } if isNil(i) { - return NoRowsAffected, fmt.Errorf("update: interface is missing %w", ErrNilParameter) + return NoRowsAffected, fmt.Errorf("update: interface is missing %w", ErrInvalidParameter) } if len(fieldMaskPaths) == 0 && len(setToNullPaths) == 0 { return NoRowsAffected, errors.New("update: both fieldMaskPaths and setToNullPaths are missing") @@ -492,10 +492,10 @@ func (rw *Db) Update(ctx context.Context, i interface{}, fieldMaskPaths []string // deleted and any errors. func (rw *Db) Delete(ctx context.Context, i interface{}, opt ...Option) (int, error) { if rw.underlying == nil { - return NoRowsAffected, fmt.Errorf("delete: missing underlying db %w", ErrNilParameter) + return NoRowsAffected, fmt.Errorf("delete: missing underlying db %w", ErrInvalidParameter) } if isNil(i) { - return NoRowsAffected, fmt.Errorf("delete: interface is missing %w", ErrNilParameter) + return NoRowsAffected, fmt.Errorf("delete: interface is missing %w", ErrInvalidParameter) } opts := GetOpts(opt...) withOplog := opts.withOplog @@ -555,7 +555,7 @@ func (rw *Db) Delete(ctx context.Context, i interface{}, opt ...Option) (int, er // together. func (rw *Db) DeleteItems(ctx context.Context, deleteItems []interface{}, opt ...Option) (int, error) { if rw.underlying == nil { - return NoRowsAffected, fmt.Errorf("delete items: missing underlying db: %w", ErrNilParameter) + return NoRowsAffected, fmt.Errorf("delete items: missing underlying db: %w", ErrInvalidParameter) } if len(deleteItems) == 0 { return NoRowsAffected, fmt.Errorf("delete items: no interfaces to delete: %w", ErrInvalidParameter) @@ -621,7 +621,7 @@ func (rw *Db) DeleteItems(ctx context.Context, deleteItems []interface{}, opt .. func validateOplogArgs(i interface{}, opts Options) (oplog.ReplayableMessage, error) { oplogArgs := opts.oplogOpts if oplogArgs.wrapper == nil { - return nil, fmt.Errorf("error no wrapper WithOplog: %w", ErrNilParameter) + return nil, fmt.Errorf("error no wrapper WithOplog: %w", ErrInvalidParameter) } if len(oplogArgs.metadata) == 0 { return nil, fmt.Errorf("error no metadata for WithOplog: %w", ErrInvalidParameter) @@ -635,7 +635,7 @@ func validateOplogArgs(i interface{}, opts Options) (oplog.ReplayableMessage, er func (rw *Db) getTicketFor(aggregateName string) (*store.Ticket, error) { if rw.underlying == nil { - return nil, fmt.Errorf("get ticket for %s: underlying db missing: %w", aggregateName, ErrNilParameter) + return nil, fmt.Errorf("get ticket for %s: underlying db missing: %w", aggregateName, ErrInvalidParameter) } ticketer, err := oplog.NewGormTicketer(rw.underlying, oplog.WithAggregateNames(true)) if err != nil { @@ -652,10 +652,10 @@ func (rw *Db) getTicketFor(aggregateName string) (*store.Ticket, error) { // be used to WriteOplogEntryWith for that aggregate root. func (rw *Db) GetTicket(i interface{}) (*store.Ticket, error) { if rw.underlying == nil { - return nil, fmt.Errorf("get ticket: underlying db missing: %w", ErrNilParameter) + return nil, fmt.Errorf("get ticket: underlying db missing: %w", ErrInvalidParameter) } if isNil(i) { - return nil, fmt.Errorf("get ticket: interface is missing %w", ErrNilParameter) + return nil, fmt.Errorf("get ticket: interface is missing %w", ErrInvalidParameter) } replayable, ok := i.(oplog.ReplayableMessage) if !ok { @@ -693,19 +693,19 @@ func (rw *Db) oplogMsgsForItems(ctx context.Context, opType OpType, opts Options func (rw *Db) addOplogForItems(ctx context.Context, opType OpType, opts Options, ticket *store.Ticket, items []interface{}) error { oplogArgs := opts.oplogOpts if ticket == nil { - return fmt.Errorf("oplog for items: ticket is missing: %w", ErrNilParameter) + return fmt.Errorf("oplog for items: ticket is missing: %w", ErrInvalidParameter) } if items == nil { - return fmt.Errorf("oplog for items: items are missing: %w", ErrNilParameter) + return fmt.Errorf("oplog for items: items are missing: %w", ErrInvalidParameter) } if len(items) == 0 { return fmt.Errorf("oplog for items: items is empty: %w", ErrInvalidParameter) } if oplogArgs.metadata == nil { - return fmt.Errorf("oplog for items: metadata is missing: %w", ErrNilParameter) + return fmt.Errorf("oplog for items: metadata is missing: %w", ErrInvalidParameter) } if oplogArgs.wrapper == nil { - return fmt.Errorf("oplog for items: wrapper is missing: %w", ErrNilParameter) + return fmt.Errorf("oplog for items: wrapper is missing: %w", ErrInvalidParameter) } oplogMsgs, err := rw.oplogMsgsForItems(ctx, opType, opts, items) @@ -748,7 +748,7 @@ func (rw *Db) addOplog(ctx context.Context, opType OpType, opts Options, ticket return err } if ticket == nil { - return fmt.Errorf("add oplog: missing ticket %w", ErrNilParameter) + return fmt.Errorf("add oplog: missing ticket %w", ErrInvalidParameter) } ticketer, err := oplog.NewGormTicketer(rw.underlying, oplog.WithAggregateNames(true)) if err != nil { @@ -783,19 +783,19 @@ func (rw *Db) addOplog(ctx context.Context, opType OpType, opts Options, ticket // the ticket's aggregateName. No options are currently supported. func (rw *Db) WriteOplogEntryWith(ctx context.Context, wrapper wrapping.Wrapper, ticket *store.Ticket, metadata oplog.Metadata, msgs []*oplog.Message, opt ...Option) error { if wrapper == nil { - return fmt.Errorf("write oplog: wrapper is unset %w", ErrNilParameter) + return fmt.Errorf("write oplog: wrapper is unset %w", ErrInvalidParameter) } if ticket == nil { - return fmt.Errorf("write oplog: ticket is unset %w", ErrNilParameter) + return fmt.Errorf("write oplog: ticket is unset %w", ErrInvalidParameter) } if len(msgs) == 0 { return fmt.Errorf("write oplog: msgs are empty %w", ErrInvalidParameter) } if rw.underlying == nil { - return fmt.Errorf("write oplog: underlying is unset %w", ErrNilParameter) + return fmt.Errorf("write oplog: underlying is unset %w", ErrInvalidParameter) } if metadata == nil { - return fmt.Errorf("write oplog: metadata is unset %w", ErrNilParameter) + return fmt.Errorf("write oplog: metadata is unset %w", ErrInvalidParameter) } if len(metadata) == 0 { return fmt.Errorf("write oplog: metadata is empty %w", ErrInvalidParameter) @@ -918,7 +918,7 @@ func (rw *Db) LookupByName(ctx context.Context, resource ResourceNamer, opt ...O // must be unique. Options are ignored. func (rw *Db) LookupById(ctx context.Context, resourceWithIder interface{}, opt ...Option) error { if rw.underlying == nil { - return fmt.Errorf("lookup by id: underlying db nil %w", ErrNilParameter) + return fmt.Errorf("lookup by id: underlying db nil %w", ErrInvalidParameter) } if reflect.ValueOf(resourceWithIder).Kind() != reflect.Ptr { return fmt.Errorf("lookup by id: interface parameter must to be a pointer: %w", ErrInvalidParameter) diff --git a/internal/db/read_writer_test.go b/internal/db/read_writer_test.go index e32f29593..669ca2779 100644 --- a/internal/db/read_writer_test.go +++ b/internal/db/read_writer_test.go @@ -303,7 +303,7 @@ func TestDb_Update(t *testing.T) { }, want: 0, wantErr: true, - wantErrMsg: "update: interface is missing nil parameter", + wantErrMsg: "update: interface is missing invalid parameter", }, { name: "only read-only", @@ -529,7 +529,7 @@ func TestDb_Update(t *testing.T) { rowsUpdated, err := w.Update(context.Background(), user, []string{"Name"}, nil) assert.Error(err) assert.Equal(0, rowsUpdated) - assert.Equal("update: missing underlying db nil parameter", err.Error()) + assert.Equal("update: missing underlying db invalid parameter", err.Error()) }) t.Run("no-wrapper-WithOplog", func(t *testing.T) { assert, require := assert.New(t), require.New(t) @@ -551,7 +551,7 @@ func TestDb_Update(t *testing.T) { ) require.Error(err) assert.Equal(0, rowsUpdated) - assert.Equal("update: oplog validation failed: error no wrapper WithOplog: nil parameter", err.Error()) + assert.Equal("update: oplog validation failed: error no wrapper WithOplog: invalid parameter", err.Error()) }) t.Run("no-metadata-WithOplog", func(t *testing.T) { assert, require := assert.New(t), require.New(t) @@ -749,7 +749,7 @@ func TestDb_Create(t *testing.T) { ), ) require.Error(err) - assert.Equal("create: oplog validation failed: error no wrapper WithOplog: nil parameter", err.Error()) + assert.Equal("create: oplog validation failed: error no wrapper WithOplog: invalid parameter", err.Error()) }) t.Run("no-metadata-WithOplog", func(t *testing.T) { assert, require := assert.New(t), require.New(t) @@ -780,7 +780,7 @@ func TestDb_Create(t *testing.T) { user.Name = "foo-" + id err = w.Create(context.Background(), user) require.Error(err) - assert.Equal("create: missing underlying db: nil parameter", err.Error()) + assert.Equal("create: missing underlying db: invalid parameter", err.Error()) }) } @@ -869,7 +869,7 @@ func TestDb_LookupByPublicId(t *testing.T) { require.NoError(err) err = w.LookupByPublicId(context.Background(), foundUser) require.Error(err) - assert.Equal("lookup by id: underlying db nil nil parameter", err.Error()) + assert.Equal("lookup by id: underlying db nil invalid parameter", err.Error()) }) t.Run("no-public-id-set", func(t *testing.T) { assert, require := assert.New(t), require.New(t) @@ -1087,7 +1087,7 @@ func TestDb_DB(t *testing.T) { d, err := w.DB() require.Error(err) assert.Nil(d) - assert.Equal("missing underlying db: nil parameter", err.Error()) + assert.Equal("missing underlying db: invalid parameter", err.Error()) }) } @@ -1334,7 +1334,7 @@ func TestDb_Delete(t *testing.T) { wantOplog: true, want: 0, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "nil-metadata", @@ -1347,7 +1347,7 @@ func TestDb_Delete(t *testing.T) { wantOplog: true, want: 0, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "nil-underlying", @@ -1358,7 +1358,7 @@ func TestDb_Delete(t *testing.T) { }, want: 0, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "not-found", @@ -1625,7 +1625,7 @@ func TestDb_CreateItems(t *testing.T) { }, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "bad oplog opt: nil wrapper", @@ -1643,7 +1643,7 @@ func TestDb_CreateItems(t *testing.T) { }, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "bad opt: WithLookup", @@ -1653,7 +1653,7 @@ func TestDb_CreateItems(t *testing.T) { opt: []Option{WithLookup(true)}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "nil underlying", @@ -1662,7 +1662,7 @@ func TestDb_CreateItems(t *testing.T) { createItems: createFn(), }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "empty items", @@ -1822,7 +1822,7 @@ func TestDb_DeleteItems(t *testing.T) { }, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "bad oplog opt: nil wrapper", @@ -1840,7 +1840,7 @@ func TestDb_DeleteItems(t *testing.T) { }, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "bad opt: WithLookup", @@ -1850,7 +1850,7 @@ func TestDb_DeleteItems(t *testing.T) { opt: []Option{WithLookup(true)}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "nil underlying", @@ -1859,7 +1859,7 @@ func TestDb_DeleteItems(t *testing.T) { deleteItems: createFn(), }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "empty items", @@ -2059,7 +2059,7 @@ func TestDb_LookupById(t *testing.T) { resourceWithIder: user, }, wantErr: true, - wantIsErr: ErrNilParameter, + wantIsErr: ErrInvalidParameter, }, } for _, tt := range tests { @@ -2120,14 +2120,14 @@ func TestDb_GetTicket(t *testing.T) { underlying: db, aggregateType: nil, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "no-underlying", underlying: nil, aggregateType: &db_test.TestUser{}, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, } for _, tt := range tests { @@ -2223,7 +2223,7 @@ func TestDb_WriteOplogEntryWith(t *testing.T) { msgs: []*oplog.Message{&createMsg}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "missing-db", @@ -2235,7 +2235,7 @@ func TestDb_WriteOplogEntryWith(t *testing.T) { msgs: []*oplog.Message{&createMsg}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "missing-wrapper", @@ -2247,7 +2247,7 @@ func TestDb_WriteOplogEntryWith(t *testing.T) { msgs: []*oplog.Message{&createMsg}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "nil-metadata", @@ -2259,7 +2259,7 @@ func TestDb_WriteOplogEntryWith(t *testing.T) { msgs: []*oplog.Message{&createMsg}, }, wantErr: true, - wantErrIs: ErrNilParameter, + wantErrIs: ErrInvalidParameter, }, { name: "empty-metadata", diff --git a/internal/host/static/repository.go b/internal/host/static/repository.go index 5ecacc54f..bd7316441 100644 --- a/internal/host/static/repository.go +++ b/internal/host/static/repository.go @@ -26,11 +26,11 @@ type Repository struct { func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) { switch { case r == nil: - return nil, fmt.Errorf("db.Reader: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Reader: %w", db.ErrInvalidParameter) case w == nil: - return nil, fmt.Errorf("db.Writer: %w", db.ErrNilParameter) + return nil, fmt.Errorf("db.Writer: %w", db.ErrInvalidParameter) case kms == nil: - return nil, fmt.Errorf("kms: %w", db.ErrNilParameter) + return nil, fmt.Errorf("kms: %w", db.ErrInvalidParameter) } opts := getOpts(opt...) diff --git a/internal/host/static/repository_host.go b/internal/host/static/repository_host.go index ce2982e42..de9b482d3 100644 --- a/internal/host/static/repository_host.go +++ b/internal/host/static/repository_host.go @@ -23,10 +23,10 @@ import ( // unique within h.CatalogId. func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, opt ...Option) (*Host, error) { if h == nil { - return nil, fmt.Errorf("create: static host: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host: %w", db.ErrInvalidParameter) } if h.Host == nil { - return nil, fmt.Errorf("create: static host: embedded Host: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host: embedded Host: %w", db.ErrInvalidParameter) } if h.CatalogId == "" { return nil, fmt.Errorf("create: static host: no catalog id: %w", db.ErrInvalidParameter) @@ -35,7 +35,7 @@ func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, op return nil, fmt.Errorf("create: static host: public id not empty: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("create: static host: no scopeId: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host: no scopeId: %w", db.ErrInvalidParameter) } h = h.clone() @@ -86,10 +86,10 @@ func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, op // in h is the zero value and it is included in fieldMaskPaths. func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, version uint32, fieldMaskPaths []string, opt ...Option) (*Host, int, error) { if h == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host: %w", db.ErrInvalidParameter) } if h.Host == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host: embedded Host: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host: embedded Host: %w", db.ErrInvalidParameter) } if h.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: static host: missing public id: %w", db.ErrInvalidParameter) @@ -98,7 +98,7 @@ func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, ve return nil, db.NoRowsAffected, fmt.Errorf("update: static host: no version supplied: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host: no scopeId: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host: no scopeId: %w", db.ErrInvalidParameter) } for _, f := range fieldMaskPaths { diff --git a/internal/host/static/repository_host_catalog.go b/internal/host/static/repository_host_catalog.go index e2068a07b..469638ac3 100644 --- a/internal/host/static/repository_host_catalog.go +++ b/internal/host/static/repository_host_catalog.go @@ -22,10 +22,10 @@ import ( // Both c.CreateTime and c.UpdateTime are ignored. func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...Option) (*HostCatalog, error) { if c == nil { - return nil, fmt.Errorf("create: static host catalog: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host catalog: %w", db.ErrInvalidParameter) } if c.HostCatalog == nil { - return nil, fmt.Errorf("create: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host catalog: embedded HostCatalog: %w", db.ErrInvalidParameter) } if c.ScopeId == "" { return nil, fmt.Errorf("create: static host catalog: no scope id: %w", db.ErrInvalidParameter) @@ -86,16 +86,16 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O // in c is the zero value and it is included in fieldMask. func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, opt ...Option) (*HostCatalog, int, error) { if c == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: %w", db.ErrInvalidParameter) } if c.HostCatalog == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: embedded HostCatalog: %w", db.ErrInvalidParameter) } if c.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: missing public id: %w", db.ErrInvalidParameter) } if c.ScopeId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: missing scope id: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: missing scope id: %w", db.ErrInvalidParameter) } if len(fieldMask) == 0 { return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: %w", db.ErrEmptyFieldMask) @@ -214,7 +214,7 @@ func (r *Repository) DeleteCatalog(ctx context.Context, id string, opt ...Option return db.NoRowsAffected, fmt.Errorf("delete: static host catalog: failed %w for %s", err, id) } if c.ScopeId == "" { - return db.NoRowsAffected, fmt.Errorf("delete: static host catalog: missing scope id: %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete: static host catalog: missing scope id: %w", db.ErrInvalidParameter) } oplogWrapper, err := r.kms.GetWrapper(ctx, c.ScopeId, kms.KeyPurposeOplog) if err != nil { diff --git a/internal/host/static/repository_host_catalog_test.go b/internal/host/static/repository_host_catalog_test.go index a45b6a71c..e6f7b02cc 100644 --- a/internal/host/static/repository_host_catalog_test.go +++ b/internal/host/static/repository_host_catalog_test.go @@ -29,12 +29,12 @@ func TestRepository_CreateCatalog(t *testing.T) { }{ { name: "nil-catalog", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-catalog", in: &HostCatalog{}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "valid-no-options", @@ -245,7 +245,7 @@ func TestRepository_UpdateCatalog(t *testing.T) { }, chgFn: makeNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-catalog", @@ -254,7 +254,7 @@ func TestRepository_UpdateCatalog(t *testing.T) { }, chgFn: makeEmbeddedNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "no-public-id", diff --git a/internal/host/static/repository_host_set.go b/internal/host/static/repository_host_set.go index 1f77eb1b5..f89ba0803 100644 --- a/internal/host/static/repository_host_set.go +++ b/internal/host/static/repository_host_set.go @@ -21,10 +21,10 @@ import ( // unique within s.CatalogId. func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, opt ...Option) (*HostSet, error) { if s == nil { - return nil, fmt.Errorf("create: static host set: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host set: %w", db.ErrInvalidParameter) } if s.HostSet == nil { - return nil, fmt.Errorf("create: static host set: embedded HostSet: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host set: embedded HostSet: %w", db.ErrInvalidParameter) } if s.CatalogId == "" { return nil, fmt.Errorf("create: static host set: no catalog id: %w", db.ErrInvalidParameter) @@ -33,7 +33,7 @@ func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, return nil, fmt.Errorf("create: static host set: public id not empty: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, fmt.Errorf("create: static host set: no scopeId: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create: static host set: no scopeId: %w", db.ErrInvalidParameter) } s = s.clone() @@ -79,10 +79,10 @@ func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, // in s is the zero value and it is included in fieldMaskPaths. func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet, version uint32, fieldMaskPaths []string, opt ...Option) (*HostSet, int, error) { if s == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: %w", db.ErrInvalidParameter) } if s.HostSet == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: embedded HostSet: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: embedded HostSet: %w", db.ErrInvalidParameter) } if s.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: missing public id: %w", db.ErrInvalidParameter) @@ -91,7 +91,7 @@ func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet, return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: no version supplied: %w", db.ErrInvalidParameter) } if scopeId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: no scopeId: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update: static host set: no scopeId: %w", db.ErrInvalidParameter) } for _, f := range fieldMaskPaths { @@ -191,7 +191,7 @@ func (r *Repository) DeleteSet(ctx context.Context, scopeId string, publicId str return db.NoRowsAffected, fmt.Errorf("delete: static host set: missing public id: %w", db.ErrInvalidParameter) } if scopeId == "" { - return db.NoRowsAffected, fmt.Errorf("delete: static host set: no scopeId: %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete: static host set: no scopeId: %w", db.ErrInvalidParameter) } s := allocHostSet() s.PublicId = publicId diff --git a/internal/host/static/repository_host_set_test.go b/internal/host/static/repository_host_set_test.go index 63628a2b5..c11129590 100644 --- a/internal/host/static/repository_host_set_test.go +++ b/internal/host/static/repository_host_set_test.go @@ -37,12 +37,12 @@ func TestRepository_CreateSet(t *testing.T) { }{ { name: "nil-HostSet", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-HostSet", in: &HostSet{}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "invalid-no-catalog-id", @@ -273,7 +273,7 @@ func TestRepository_UpdateSet(t *testing.T) { }, chgFn: makeNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-host-set", @@ -282,7 +282,7 @@ func TestRepository_UpdateSet(t *testing.T) { }, chgFn: makeEmbeddedNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "no-public-id", diff --git a/internal/host/static/repository_host_test.go b/internal/host/static/repository_host_test.go index a7817ef57..c7d407b6d 100644 --- a/internal/host/static/repository_host_test.go +++ b/internal/host/static/repository_host_test.go @@ -37,12 +37,12 @@ func TestRepository_CreateHost(t *testing.T) { }{ { name: "nil-Host", - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-Host", in: &Host{}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "invalid-no-catalog-id", @@ -320,7 +320,7 @@ func TestRepository_UpdateHost(t *testing.T) { }, chgFn: makeNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-embedded-host", @@ -331,7 +331,7 @@ func TestRepository_UpdateHost(t *testing.T) { }, chgFn: makeEmbeddedNil(), masks: []string{"Name", "Description"}, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "no-public-id", diff --git a/internal/host/static/repository_test.go b/internal/host/static/repository_test.go index 659eece99..e144011e2 100644 --- a/internal/host/static/repository_test.go +++ b/internal/host/static/repository_test.go @@ -67,7 +67,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-writer", @@ -77,7 +77,7 @@ func TestRepository_New(t *testing.T) { kms: kmsCache, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-kms", @@ -87,7 +87,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "all-nils", @@ -97,7 +97,7 @@ func TestRepository_New(t *testing.T) { kms: nil, }, want: nil, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, } for _, tt := range tests { diff --git a/internal/iam/repository_group.go b/internal/iam/repository_group.go index 7bdfbee3f..1c60aed72 100644 --- a/internal/iam/repository_group.go +++ b/internal/iam/repository_group.go @@ -15,10 +15,10 @@ import ( // group. No options are currently supported. func (r *Repository) CreateGroup(ctx context.Context, group *Group, opt ...Option) (*Group, error) { if group == nil { - return nil, fmt.Errorf("create group: missing group %w", db.ErrNilParameter) + return nil, fmt.Errorf("create group: missing group %w", db.ErrInvalidParameter) } if group.Group == nil { - return nil, fmt.Errorf("create group: missing group store %w", db.ErrNilParameter) + return nil, fmt.Errorf("create group: missing group store %w", db.ErrInvalidParameter) } if group.PublicId != "" { return nil, fmt.Errorf("create group: public id not empty: %w", db.ErrInvalidParameter) @@ -49,10 +49,10 @@ func (r *Repository) CreateGroup(ctx context.Context, group *Group, opt ...Optio // If no updatable fields are included in the fieldMaskPaths, then an error is returned. func (r *Repository) UpdateGroup(ctx context.Context, group *Group, version uint32, fieldMaskPaths []string, opt ...Option) (*Group, []*GroupMember, int, error) { if group == nil { - return nil, nil, db.NoRowsAffected, fmt.Errorf("update group: missing group %w", db.ErrNilParameter) + return nil, nil, db.NoRowsAffected, fmt.Errorf("update group: missing group %w", db.ErrInvalidParameter) } if group.Group == nil { - return nil, nil, db.NoRowsAffected, fmt.Errorf("update group: missing group store %w", db.ErrNilParameter) + return nil, nil, db.NoRowsAffected, fmt.Errorf("update group: missing group store %w", db.ErrInvalidParameter) } if group.PublicId == "" { return nil, nil, db.NoRowsAffected, fmt.Errorf("update group: missing group public id %w", db.ErrInvalidParameter) @@ -114,7 +114,7 @@ func (r *Repository) UpdateGroup(ctx context.Context, group *Group, version uint // found, it will return nil, nil. func (r *Repository) LookupGroup(ctx context.Context, withPublicId string, opt ...Option) (*Group, []*GroupMember, error) { if withPublicId == "" { - return nil, nil, fmt.Errorf("lookup group: missing public id %w", db.ErrNilParameter) + return nil, nil, fmt.Errorf("lookup group: missing public id %w", db.ErrInvalidParameter) } g := allocGroup() g.PublicId = withPublicId @@ -147,7 +147,7 @@ func (r *Repository) LookupGroup(ctx context.Context, withPublicId string, opt . // DeleteGroup will delete a group from the repository. func (r *Repository) DeleteGroup(ctx context.Context, withPublicId string, opt ...Option) (int, error) { if withPublicId == "" { - return db.NoRowsAffected, fmt.Errorf("delete group: missing public id %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete group: missing public id %w", db.ErrInvalidParameter) } g := allocGroup() g.PublicId = withPublicId diff --git a/internal/iam/repository_group_test.go b/internal/iam/repository_group_test.go index 4714e309a..65829044f 100644 --- a/internal/iam/repository_group_test.go +++ b/internal/iam/repository_group_test.go @@ -80,8 +80,8 @@ func TestRepository_CreateGroup(t *testing.T) { group: nil, }, wantErr: true, - wantErrMsg: "create group: missing group nil parameter", - wantIsError: db.ErrNilParameter, + wantErrMsg: "create group: missing group invalid parameter", + wantIsError: db.ErrInvalidParameter, }, { name: "nil-store", @@ -93,8 +93,8 @@ func TestRepository_CreateGroup(t *testing.T) { }(), }, wantErr: true, - wantErrMsg: "create group: missing group store nil parameter", - wantIsError: db.ErrNilParameter, + wantErrMsg: "create group: missing group store invalid parameter", + wantIsError: db.ErrInvalidParameter, }, { name: "bad-scope-id", @@ -503,7 +503,7 @@ func TestRepository_DeleteGroup(t *testing.T) { }, wantRowsDeleted: 0, wantErr: true, - wantErrMsg: "delete group: missing public id nil parameter", + wantErrMsg: "delete group: missing public id invalid parameter", }, { name: "not-found", diff --git a/internal/iam/repository_principal_role.go b/internal/iam/repository_principal_role.go index 64d97962a..7c2ff1916 100644 --- a/internal/iam/repository_principal_role.go +++ b/internal/iam/repository_principal_role.go @@ -409,7 +409,7 @@ type principalSet struct { // TODO: Should this be moved inside the transaction, at this point? func (r *Repository) principalsToSet(ctx context.Context, role *Role, userIds, groupIds []string) (*principalSet, error) { if role == nil { - return nil, fmt.Errorf("missing role: %w", db.ErrNilParameter) + return nil, fmt.Errorf("missing role: %w", db.ErrInvalidParameter) } existing, err := r.ListPrincipalRoles(ctx, role.PublicId) if err != nil { diff --git a/internal/iam/repository_principal_role_test.go b/internal/iam/repository_principal_role_test.go index 4a5c16f82..e444fe07d 100644 --- a/internal/iam/repository_principal_role_test.go +++ b/internal/iam/repository_principal_role_test.go @@ -772,7 +772,7 @@ func TestRepository_principalsToSet(t *testing.T) { got, err := repo.principalsToSet(context.Background(), nil, users, grps) require.Error(err) assert.Nil(got) - assert.Truef(errors.Is(err, db.ErrNilParameter), "unexpected error %s", err.Error()) + assert.Truef(errors.Is(err, db.ErrInvalidParameter), "unexpected error %s", err.Error()) }) t.Run("no change", func(t *testing.T) { assert, require := assert.New(t), require.New(t) diff --git a/internal/iam/repository_role.go b/internal/iam/repository_role.go index 9a6aad4a3..5daaf2973 100644 --- a/internal/iam/repository_role.go +++ b/internal/iam/repository_role.go @@ -13,10 +13,10 @@ import ( // role. No options are currently supported. func (r *Repository) CreateRole(ctx context.Context, role *Role, opt ...Option) (*Role, error) { if role == nil { - return nil, fmt.Errorf("create role: missing role %w", db.ErrNilParameter) + return nil, fmt.Errorf("create role: missing role %w", db.ErrInvalidParameter) } if role.Role == nil { - return nil, fmt.Errorf("create role: missing role store %w", db.ErrNilParameter) + return nil, fmt.Errorf("create role: missing role store %w", db.ErrInvalidParameter) } if role.PublicId != "" { return nil, fmt.Errorf("create role: public id not empty: %w", db.ErrInvalidParameter) @@ -48,10 +48,10 @@ func (r *Repository) CreateRole(ctx context.Context, role *Role, opt ...Option) // then an error is returned. func (r *Repository) UpdateRole(ctx context.Context, role *Role, version uint32, fieldMaskPaths []string, opt ...Option) (*Role, []PrincipalRole, []*RoleGrant, int, error) { if role == nil { - return nil, nil, nil, db.NoRowsAffected, fmt.Errorf("update role: missing role %w", db.ErrNilParameter) + return nil, nil, nil, db.NoRowsAffected, fmt.Errorf("update role: missing role %w", db.ErrInvalidParameter) } if role.Role == nil { - return nil, nil, nil, db.NoRowsAffected, fmt.Errorf("update role: missing role store %w", db.ErrNilParameter) + return nil, nil, nil, db.NoRowsAffected, fmt.Errorf("update role: missing role store %w", db.ErrInvalidParameter) } if role.PublicId == "" { return nil, nil, nil, db.NoRowsAffected, fmt.Errorf("update role: missing role public id %w", db.ErrInvalidParameter) @@ -120,7 +120,7 @@ func (r *Repository) UpdateRole(ctx context.Context, role *Role, version uint32, // found, it will return nil, nil. func (r *Repository) LookupRole(ctx context.Context, withPublicId string, opt ...Option) (*Role, []PrincipalRole, []*RoleGrant, error) { if withPublicId == "" { - return nil, nil, nil, fmt.Errorf("lookup role: missing public id %w", db.ErrNilParameter) + return nil, nil, nil, fmt.Errorf("lookup role: missing public id %w", db.ErrInvalidParameter) } role := allocRole() role.PublicId = withPublicId @@ -158,7 +158,7 @@ func (r *Repository) LookupRole(ctx context.Context, withPublicId string, opt .. // DeleteRole will delete a role from the repository. func (r *Repository) DeleteRole(ctx context.Context, withPublicId string, opt ...Option) (int, error) { if withPublicId == "" { - return db.NoRowsAffected, fmt.Errorf("delete role: missing public id %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete role: missing public id %w", db.ErrInvalidParameter) } role := allocRole() role.PublicId = withPublicId diff --git a/internal/iam/repository_role_grant.go b/internal/iam/repository_role_grant.go index 2ab53f7f6..9709ddc36 100644 --- a/internal/iam/repository_role_grant.go +++ b/internal/iam/repository_role_grant.go @@ -225,7 +225,7 @@ func (r *Repository) SetRoleGrants(ctx context.Context, roleId string, roleVersi // Explicitly set to zero clears, but treat nil as a mistake if grants == nil { - return nil, db.NoRowsAffected, fmt.Errorf("set role grants: nil grants: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("set role grants: nil grants: %w", db.ErrInvalidParameter) } role := allocRole() diff --git a/internal/iam/repository_role_test.go b/internal/iam/repository_role_test.go index 2d422777c..336588173 100644 --- a/internal/iam/repository_role_test.go +++ b/internal/iam/repository_role_test.go @@ -81,8 +81,8 @@ func TestRepository_CreateRole(t *testing.T) { role: nil, }, wantErr: true, - wantErrMsg: "create role: missing role nil parameter", - wantIsError: db.ErrNilParameter, + wantErrMsg: "create role: missing role invalid parameter", + wantIsError: db.ErrInvalidParameter, }, { name: "nil-store", @@ -94,8 +94,8 @@ func TestRepository_CreateRole(t *testing.T) { }(), }, wantErr: true, - wantErrMsg: "create role: missing role store nil parameter", - wantIsError: db.ErrNilParameter, + wantErrMsg: "create role: missing role store invalid parameter", + wantIsError: db.ErrInvalidParameter, }, { name: "bad-scope-id", @@ -500,7 +500,7 @@ func TestRepository_DeleteRole(t *testing.T) { }, wantRowsDeleted: 0, wantErr: true, - wantErrMsg: "delete role: missing public id nil parameter", + wantErrMsg: "delete role: missing public id invalid parameter", }, { name: "not-found", diff --git a/internal/iam/repository_scope.go b/internal/iam/repository_scope.go index 9c9f9a0dc..e60956078 100644 --- a/internal/iam/repository_scope.go +++ b/internal/iam/repository_scope.go @@ -22,10 +22,10 @@ import ( // scope. Supported options include: WithPublicId and WithRandomReader. func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, opt ...Option) (*Scope, error) { if s == nil { - return nil, fmt.Errorf("create scope: missing scope %w", db.ErrNilParameter) + return nil, fmt.Errorf("create scope: missing scope %w", db.ErrInvalidParameter) } if s.Scope == nil { - return nil, fmt.Errorf("create scope: missing scope store %w", db.ErrNilParameter) + return nil, fmt.Errorf("create scope: missing scope store %w", db.ErrInvalidParameter) } if s.PublicId != "" { return nil, fmt.Errorf("create scope: public id not empty: %w", db.ErrInvalidParameter) @@ -42,7 +42,7 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o default: switch s.ParentId { case "": - return nil, fmt.Errorf("create scope: missing parent id: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create scope: missing parent id: %w", db.ErrInvalidParameter) case scope.Global.String(): parentOplogWrapper, err = r.kms.GetWrapper(ctx, scope.Global.String(), kms.KeyPurposeOplog) default: @@ -242,10 +242,10 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o // fieldMaskPaths, then an error is returned. func (r *Repository) UpdateScope(ctx context.Context, scope *Scope, version uint32, fieldMaskPaths []string, opt ...Option) (*Scope, int, error) { if scope == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update scope: missing scope: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update scope: missing scope: %w", db.ErrInvalidParameter) } if scope.PublicId == "" { - return nil, db.NoRowsAffected, fmt.Errorf("update scope: missing public id: %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update scope: missing public id: %w", db.ErrInvalidParameter) } if contains(fieldMaskPaths, "ParentId") { return nil, db.NoRowsAffected, fmt.Errorf("update scope: you cannot change a scope's parent: %w", db.ErrInvalidFieldMask) diff --git a/internal/iam/repository_scope_test.go b/internal/iam/repository_scope_test.go index 3abb2bdb0..9d7f243ab 100644 --- a/internal/iam/repository_scope_test.go +++ b/internal/iam/repository_scope_test.go @@ -289,7 +289,7 @@ func TestRepository_UpdateScope(t *testing.T) { }, wantUpdatedRows: 0, wantErr: true, - wantErrMsg: "update scope: missing scope: nil parameter", + wantErrMsg: "update scope: missing scope: invalid parameter", wantNullFields: nil, }, { diff --git a/internal/iam/repository_user.go b/internal/iam/repository_user.go index c322fc573..590145f24 100644 --- a/internal/iam/repository_user.go +++ b/internal/iam/repository_user.go @@ -15,7 +15,7 @@ import ( // CreateUser will create a user in the repository and return the written user func (r *Repository) CreateUser(ctx context.Context, user *User, opt ...Option) (*User, error) { if user == nil { - return nil, fmt.Errorf("create user: missing user %w", db.ErrNilParameter) + return nil, fmt.Errorf("create user: missing user %w", db.ErrInvalidParameter) } if user.PublicId != "" { return nil, fmt.Errorf("create user: public id is not empty %w", db.ErrInvalidParameter) @@ -43,7 +43,7 @@ func (r *Repository) CreateUser(ctx context.Context, user *User, opt ...Option) // If no updatable fields are included in the fieldMaskPaths, then an error is returned. func (r *Repository) UpdateUser(ctx context.Context, user *User, version uint32, fieldMaskPaths []string, opt ...Option) (*User, int, error) { if user == nil { - return nil, db.NoRowsAffected, fmt.Errorf("update user: missing user %w", db.ErrNilParameter) + return nil, db.NoRowsAffected, fmt.Errorf("update user: missing user %w", db.ErrInvalidParameter) } if user.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update user: missing user public id %w", db.ErrInvalidParameter) @@ -83,7 +83,7 @@ func (r *Repository) UpdateUser(ctx context.Context, user *User, version uint32, // found, it will return nil, nil. func (r *Repository) LookupUser(ctx context.Context, withPublicId string, opt ...Option) (*User, error) { if withPublicId == "" { - return nil, fmt.Errorf("lookup user: missing public id %w", db.ErrNilParameter) + return nil, fmt.Errorf("lookup user: missing public id %w", db.ErrInvalidParameter) } user := allocUser() @@ -97,7 +97,7 @@ func (r *Repository) LookupUser(ctx context.Context, withPublicId string, opt .. // DeleteUser will delete a user from the repository func (r *Repository) DeleteUser(ctx context.Context, withPublicId string, opt ...Option) (int, error) { if withPublicId == "" { - return db.NoRowsAffected, fmt.Errorf("delete user: missing public id %w", db.ErrNilParameter) + return db.NoRowsAffected, fmt.Errorf("delete user: missing public id %w", db.ErrInvalidParameter) } user := allocUser() user.PublicId = withPublicId diff --git a/internal/iam/repository_user_test.go b/internal/iam/repository_user_test.go index 932706a5a..b95d426b7 100644 --- a/internal/iam/repository_user_test.go +++ b/internal/iam/repository_user_test.go @@ -402,7 +402,7 @@ func TestRepository_DeleteUser(t *testing.T) { }, wantRowsDeleted: 0, wantErr: true, - wantErrMsg: "delete user: missing public id nil parameter", + wantErrMsg: "delete user: missing public id invalid parameter", }, { name: "not-found", diff --git a/internal/iam/role_grant.go b/internal/iam/role_grant.go index 8a8de543c..869295f85 100644 --- a/internal/iam/role_grant.go +++ b/internal/iam/role_grant.go @@ -25,10 +25,10 @@ var _ db.VetForWriter = (*RoleGrant)(nil) // NewRoleGrant creates a new in memory role grant func NewRoleGrant(roleId string, grant string, opt ...Option) (*RoleGrant, error) { if roleId == "" { - return nil, fmt.Errorf("new role grant: role id is not set: %w", db.ErrNilParameter) + return nil, fmt.Errorf("new role grant: role id is not set: %w", db.ErrInvalidParameter) } if grant == "" { - return nil, fmt.Errorf("new role grant: grant is empty: %w", db.ErrNilParameter) + return nil, fmt.Errorf("new role grant: grant is empty: %w", db.ErrInvalidParameter) } // Validate that the grant parses successfully. Note that we fake the scope @@ -65,7 +65,7 @@ func (g *RoleGrant) Clone() interface{} { // VetForWrite implements db.VetForWrite() interface func (g *RoleGrant) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, opt ...db.Option) error { if g.RawGrant == "" { - return fmt.Errorf("vet role grant for writing: grant is empty: %w", db.ErrNilParameter) + return fmt.Errorf("vet role grant for writing: grant is empty: %w", db.ErrInvalidParameter) } // Validate that the grant parses successfully. Note that we fake the scope diff --git a/internal/iam/role_grant_test.go b/internal/iam/role_grant_test.go index c6816eed7..9787007a7 100644 --- a/internal/iam/role_grant_test.go +++ b/internal/iam/role_grant_test.go @@ -41,7 +41,7 @@ func TestRoleGrant_Create(t *testing.T) { grant: "id=*;actions=*", }, wantErr: true, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, }, { name: "nil-grant", @@ -50,7 +50,7 @@ func TestRoleGrant_Create(t *testing.T) { grant: "", }, wantErr: true, - wantIsErr: db.ErrNilParameter, + wantIsErr: db.ErrInvalidParameter, create: true, }, { diff --git a/internal/iam/user.go b/internal/iam/user.go index 3402be748..495070a18 100644 --- a/internal/iam/user.go +++ b/internal/iam/user.go @@ -63,7 +63,7 @@ func (u *User) Clone() interface{} { // before it's written. func (u *User) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, opt ...db.Option) error { if u.PublicId == "" { - return fmt.Errorf("user vet for write: missing public id: %w", db.ErrNilParameter) + return fmt.Errorf("user vet for write: missing public id: %w", db.ErrInvalidParameter) } if err := validateScopeForWrite(ctx, r, u, opType, opt...); err != nil { return err diff --git a/internal/kms/common/root_test.go b/internal/kms/common/root_test.go index 41faf976b..7e5a330c3 100644 --- a/internal/kms/common/root_test.go +++ b/internal/kms/common/root_test.go @@ -92,7 +92,7 @@ func TestRepository_CreateRootKeyTx(t *testing.T) { keyWrapper: nil, }, wantErr: true, - wantIsError: db.ErrNilParameter, + wantIsError: db.ErrInvalidParameter, }, } for _, tt := range tests { diff --git a/internal/kms/repository_root_key.go b/internal/kms/repository_root_key.go index 1e55e9d71..f6d9d1de9 100644 --- a/internal/kms/repository_root_key.go +++ b/internal/kms/repository_root_key.go @@ -39,7 +39,7 @@ func CreateRootKeyTx(ctx context.Context, w db.Writer, keyWrapper wrapping.Wrapp return nil, nil, fmt.Errorf("create root key: missing scope id: %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, nil, fmt.Errorf("create root key: missing key wrapper: %w", db.ErrNilParameter) + return nil, nil, fmt.Errorf("create root key: missing key wrapper: %w", db.ErrInvalidParameter) } if len(key) == 0 { return nil, nil, fmt.Errorf("create root key: missing key: %w", db.ErrInvalidParameter) @@ -80,10 +80,10 @@ func CreateRootKeyTx(ctx context.Context, w db.Writer, keyWrapper wrapping.Wrapp // found, it will return nil, nil. func (r *Repository) LookupRootKey(ctx context.Context, keyWrapper wrapping.Wrapper, privateId string, opt ...Option) (*RootKey, error) { if privateId == "" { - return nil, fmt.Errorf("lookup root key: missing private id: %w", db.ErrNilParameter) + return nil, fmt.Errorf("lookup root key: missing private id: %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, fmt.Errorf("lookup root key: missing key wrapper: %w", db.ErrNilParameter) + return nil, fmt.Errorf("lookup root key: missing key wrapper: %w", db.ErrInvalidParameter) } k := AllocRootKey() k.PrivateId = privateId diff --git a/internal/kms/repository_root_key_test.go b/internal/kms/repository_root_key_test.go index 8d178083e..92b4f65c4 100644 --- a/internal/kms/repository_root_key_test.go +++ b/internal/kms/repository_root_key_test.go @@ -82,7 +82,7 @@ func TestRepository_CreateRootKey(t *testing.T) { keyWrapper: nil, }, wantErr: true, - wantIsError: db.ErrNilParameter, + wantIsError: db.ErrInvalidParameter, }, } for _, tt := range tests { diff --git a/internal/kms/repository_root_key_version.go b/internal/kms/repository_root_key_version.go index 9d33a7349..ec46838c9 100644 --- a/internal/kms/repository_root_key_version.go +++ b/internal/kms/repository_root_key_version.go @@ -15,7 +15,7 @@ func (r *Repository) CreateRootKeyVersion(ctx context.Context, keyWrapper wrappi return nil, fmt.Errorf("create root key version: missing root key id: %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, fmt.Errorf("create root key version: missing key wrapper: %w", db.ErrNilParameter) + return nil, fmt.Errorf("create root key version: missing key wrapper: %w", db.ErrInvalidParameter) } if len(key) == 0 { return nil, fmt.Errorf("create root key version: missing key: %w", db.ErrInvalidParameter) @@ -56,10 +56,10 @@ func (r *Repository) CreateRootKeyVersion(ctx context.Context, keyWrapper wrappi // the key version is not found, it will return nil, nil. func (r *Repository) LookupRootKeyVersion(ctx context.Context, keyWrapper wrapping.Wrapper, privateId string, opt ...Option) (*RootKeyVersion, error) { if privateId == "" { - return nil, fmt.Errorf("lookup root key version: missing private id: %w", db.ErrNilParameter) + return nil, fmt.Errorf("lookup root key version: missing private id: %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, fmt.Errorf("lookup root key version: missing key wrapper: %w", db.ErrNilParameter) + return nil, fmt.Errorf("lookup root key version: missing key wrapper: %w", db.ErrInvalidParameter) } k := AllocRootKeyVersion() k.PrivateId = privateId @@ -111,10 +111,10 @@ func (r *Repository) DeleteRootKeyVersion(ctx context.Context, privateId string, // db.ErrRecordNotFound. func (r *Repository) LatestRootKeyVersion(ctx context.Context, keyWrapper wrapping.Wrapper, rootKeyId string, opt ...Option) (*RootKeyVersion, error) { if rootKeyId == "" { - return nil, fmt.Errorf("latest root key version: missing root key id: %w", db.ErrNilParameter) + return nil, fmt.Errorf("latest root key version: missing root key id: %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, fmt.Errorf("latest root key version: missing key wrapper: %w", db.ErrNilParameter) + return nil, fmt.Errorf("latest root key version: missing key wrapper: %w", db.ErrInvalidParameter) } var foundKeys []RootKeyVersion if err := r.reader.SearchWhere(ctx, &foundKeys, "root_key_id = ?", []interface{}{rootKeyId}, db.WithLimit(1), db.WithOrder("version desc")); err != nil { @@ -135,7 +135,7 @@ func (r *Repository) ListRootKeyVersions(ctx context.Context, keyWrapper wrappin return nil, fmt.Errorf("list root key versions: missing root key id %w", db.ErrInvalidParameter) } if keyWrapper == nil { - return nil, fmt.Errorf("list root key versions: missing key wrapper: %w", db.ErrNilParameter) + return nil, fmt.Errorf("list root key versions: missing key wrapper: %w", db.ErrInvalidParameter) } var versions []*RootKeyVersion err := r.list(ctx, &versions, "root_key_id = ?", []interface{}{rootKeyId}, opt...) diff --git a/internal/kms/repository_root_key_version_test.go b/internal/kms/repository_root_key_version_test.go index e9f72da3c..fe47591b1 100644 --- a/internal/kms/repository_root_key_version_test.go +++ b/internal/kms/repository_root_key_version_test.go @@ -75,7 +75,7 @@ func TestRepository_CreateRootKeyVersion(t *testing.T) { keyWrapper: nil, }, wantErr: true, - wantIsError: db.ErrNilParameter, + wantIsError: db.ErrInvalidParameter, }, } for _, tt := range tests { @@ -238,7 +238,7 @@ func TestRepository_LatestRootKeyVersion(t *testing.T) { createCnt: 5, keyWrapper: nil, wantErr: true, - wantIsError: db.ErrNilParameter, + wantIsError: db.ErrInvalidParameter, }, } for _, tt := range tests {