Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific errors for missing kind and version. #4802

Merged
merged 1 commit into from
Feb 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions pkg/conversion/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,35 @@ func IsNotRegisteredError(err error) bool {
_, ok := err.(*notRegisteredErr)
return ok
}

type missingKindErr struct {
data string
}

func (k *missingKindErr) Error() string {
return fmt.Sprintf("Object 'Kind' is missing in '%s'", k.data)
}

func IsMissingKind(err error) bool {
if err == nil {
return false
}
_, ok := err.(*missingKindErr)
return ok
}

type missingVersionErr struct {
data string
}

func (k *missingVersionErr) Error() string {
return fmt.Sprintf("Object 'apiVersion' is missing in '%s'", k.data)
}

func IsMissingVersion(err error) bool {
if err == nil {
return false
}
_, ok := err.(*missingVersionErr)
return ok
}
12 changes: 12 additions & 0 deletions pkg/runtime/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ import (
func IsNotRegisteredError(err error) bool {
return conversion.IsNotRegisteredError(err)
}

// IsMissingKind returns true if the error indicates that the provided object
// is missing a 'Kind' field.
func IsMissingKind(err error) bool {
return conversion.IsMissingKind(err)
}

// IsMissingVersion returns true if the error indicates that the provided object
// is missing a 'Versioj' field.
func IsMissingVersion(err error) bool {
return conversion.IsMissingVersion(err)
}