Replace and remove ErrNilParameter with ErrInvalidParameter (#295)

This commit is contained in:
Michael Gaffney authored and GitHub committed 2020-08-25 12:18:14 -04:00
1 parent 8f579c75c3
commit de162c5533
44 files changed
+187 -190

No files matched your search

+3 -3
View File
@@ -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...)
+6 -6
View File
@@ -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 {
@@ -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 {
@@ -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",
+7 -7
View File
@@ -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
@@ -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",
+4 -4
View File
@@ -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",
+4 -4
View File
@@ -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 {