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

Improve error handling in clients #1154

Merged
merged 1 commit into from
Nov 30, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
|===
| | Description | PR

| 🐣
| Improve error handling in clients
| https://github.com/knative/client/pull/1154[#1154]

| 🎁
| Add machine readable output (-o flag) to kn source ping describe
| https://github.com/knative/client/pull/1150[#1150]
Expand Down
5 changes: 4 additions & 1 deletion pkg/sources/v1alpha2/apiserver_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func (c *apiServerSourcesClient) UpdateAPIServerSource(apiSource *v1alpha2.ApiSe
//DeleteAPIServerSource is used to create an instance of ApiServerSource
func (c *apiServerSourcesClient) DeleteAPIServerSource(name string) error {
err := c.client.Delete(context.TODO(), name, metav1.DeleteOptions{})
return err
if err != nil {
return knerrors.GetError(err)
}
return nil
}

// Return the client's namespace
Expand Down
18 changes: 14 additions & 4 deletions pkg/sources/v1alpha2/ping_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,26 @@ func (c *pingSourcesClient) CreatePingSource(pingsource *v1alpha2.PingSource) er
return fmt.Errorf("a sink is required for creating a source")
}
_, err := c.client.Create(context.TODO(), pingsource, metav1.CreateOptions{})
return err
if err != nil {
return knerrors.GetError(err)
}
return nil
}

func (c *pingSourcesClient) UpdatePingSource(pingSource *v1alpha2.PingSource) error {
_, err := c.client.Update(context.TODO(), pingSource, metav1.UpdateOptions{})
return err
if err != nil {
return knerrors.GetError(err)
}
return nil
}

func (c *pingSourcesClient) DeletePingSource(name string) error {
return c.client.Delete(context.TODO(), name, metav1.DeleteOptions{})
err := c.client.Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return knerrors.GetError(err)
}
return nil
}

func (c *pingSourcesClient) GetPingSource(name string) (*v1alpha2.PingSource, error) {
Expand All @@ -104,7 +114,7 @@ func (c *pingSourcesClient) GetPingSource(name string) (*v1alpha2.PingSource, er
func (c *pingSourcesClient) ListPingSource() (*v1alpha2.PingSourceList, error) {
sourceList, err := c.client.List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
return nil, knerrors.GetError(err)
}

return updatePingSourceListGVK(sourceList)
Expand Down