Skip to content

Commit 926821d

Browse files
authored
Merge pull request #165 from replicatedhq/laverya/platform-not-gql-channel-by-name
platform channel search returns ErrNotFound if not found, not gql error string
2 parents 3ee687a + d49fc7f commit 926821d

File tree

11 files changed

+24
-22
lines changed

11 files changed

+24
-22
lines changed

cli/cmd/collector_update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ func (r *runners) collectorUpdate(cmd *cobra.Command, args []string) error {
5858
if r.args.updateCollectorYaml != "" {
5959
_, err := r.api.UpdateCollector(r.appID, specID, r.args.updateCollectorYaml)
6060
if err != nil {
61-
return fmt.Errorf("Failure setting updates for collector: %v", err)
61+
return fmt.Errorf("Failure setting updates for collector: %w", err)
6262
}
6363
}
6464

6565
if r.args.updateCollectorName != "" {
6666
_, err := r.api.UpdateCollectorName(r.appID, specID, r.args.updateCollectorName)
6767
if err != nil {
68-
return fmt.Errorf("Failure setting new yaml config for collector: %v", err)
68+
return fmt.Errorf("Failure setting new yaml config for collector: %w", err)
6969
}
7070
}
7171

cli/cmd/release_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (r *runners) releaseUpdate(cmd *cobra.Command, args []string) error {
6565
}
6666
}
6767
if err := r.api.UpdateRelease(r.appID, r.appType, seq, r.args.updateReleaseYaml); err != nil {
68-
return fmt.Errorf("Failure setting new yaml config for release: %v", err)
68+
return fmt.Errorf("Failure setting new yaml config for release: %w", err)
6969
}
7070

7171
// ignore the error since operation was successful

client/channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/pkg/errors"
88
channels "github.com/replicatedhq/replicated/gen/go/v1"
9+
"github.com/replicatedhq/replicated/pkg/platformclient"
910
"github.com/replicatedhq/replicated/pkg/types"
1011
)
1112

@@ -100,7 +101,7 @@ func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug
100101
ReleaseSequence: channel.ReleaseSequence,
101102
ReleaseLabel: channel.ReleaseLabel,
102103
}, nil
103-
} else if !strings.Contains(err.Error(), gqlNotFoundErr) {
104+
} else if !strings.Contains(err.Error(), gqlNotFoundErr) && !errors.Is(err, platformclient.ErrNotFound) {
104105
return nil, errors.Wrap(err, "get channel")
105106
}
106107

pkg/enterpriseclient/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *HTTPClient) doJSON(method, path string, successStatus int, reqBody inte
8181
}
8282
if respBody != nil {
8383
if err := json.NewDecoder(resp.Body).Decode(respBody); err != nil {
84-
return fmt.Errorf("%s %s response decoding: %v", method, endpoint, err)
84+
return fmt.Errorf("%s %s response decoding: %w", method, endpoint, err)
8585
}
8686
}
8787

pkg/platformclient/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (c *HTTPClient) ListApps() ([]apps.AppAndChannels, error) {
2222
func (c *HTTPClient) GetApp(slugOrID string) (*apps.App, error) {
2323
appsAndChannels, err := c.ListApps()
2424
if err != nil {
25-
return nil, fmt.Errorf("GetApp: %v", err)
25+
return nil, fmt.Errorf("GetApp: %w", err)
2626
}
2727
for _, ac := range appsAndChannels {
2828
if ac.App.Slug == slugOrID || ac.App.Id == slugOrID {
@@ -53,7 +53,7 @@ func (c *HTTPClient) DeleteApp(id string) error {
5353
req.Header.Add("Authorization", c.apiKey)
5454
resp, err := http.DefaultClient.Do(req)
5555
if err != nil {
56-
return fmt.Errorf("DeleteApp (%s %s): %v", req.Method, endpoint, err)
56+
return fmt.Errorf("DeleteApp (%s %s): %w", req.Method, endpoint, err)
5757
}
5858
resp.Body.Close()
5959
if resp.StatusCode != http.StatusNoContent {

pkg/platformclient/channel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (c *HTTPClient) ListChannels(appID string) ([]channels.AppChannel, error) {
2929
appChannels := make([]channels.AppChannel, 0)
3030
err := c.DoJSON("GET", path, http.StatusOK, nil, &appChannels)
3131
if err != nil {
32-
return nil, fmt.Errorf("ListChannels: %v", err)
32+
return nil, fmt.Errorf("ListChannels: %w", err)
3333
}
3434
sort.Sort(AppChannels(appChannels))
3535

@@ -46,7 +46,7 @@ func (c *HTTPClient) CreateChannel(appID string, name string, description string
4646
appChannels := make([]channels.AppChannel, 0)
4747
err := c.DoJSON("POST", path, http.StatusOK, body, &appChannels)
4848
if err != nil {
49-
return fmt.Errorf("CreateChannel: %v", err)
49+
return fmt.Errorf("CreateChannel: %w", err)
5050
}
5151
return nil
5252
}
@@ -61,7 +61,7 @@ func (c *HTTPClient) ArchiveChannel(appID, channelID string) error {
6161
req.Header.Add("Authorization", c.apiKey)
6262
resp, err := http.DefaultClient.Do(req)
6363
if err != nil {
64-
return fmt.Errorf("ArchiveChannel (%s %s): %v", req.Method, endpoint, err)
64+
return fmt.Errorf("ArchiveChannel (%s %s): %w", req.Method, endpoint, err)
6565
}
6666
resp.Body.Close()
6767
if resp.StatusCode != http.StatusNoContent {
@@ -94,7 +94,7 @@ func (c *HTTPClient) GetChannel(appID, channelID string) (*channels.AppChannel,
9494
respBody := channels.GetChannelInlineResponse200{}
9595
err := c.DoJSON("GET", path, http.StatusOK, nil, &respBody)
9696
if err != nil {
97-
return nil, nil, fmt.Errorf("GetChannel: %v", err)
97+
return nil, nil, fmt.Errorf("GetChannel: %w", err)
9898
}
9999
sort.Sort(ChannelReleases(respBody.Releases))
100100
return respBody.Channel, respBody.Releases, nil

pkg/platformclient/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"bytes"
66
"encoding/json"
77
"fmt"
8-
"github.com/pkg/errors"
98
"io/ioutil"
109
"net/http"
10+
11+
"github.com/pkg/errors"
1112
)
1213

1314
const apiOrigin = "https://api.replicated.com/vendor"
@@ -76,7 +77,7 @@ func (c *HTTPClient) DoJSON(method, path string, successStatus int, reqBody, res
7677
return errors.Wrap(err, "read body")
7778
}
7879
if err := json.NewDecoder(bytes.NewReader(bodyBytes)).Decode(respBody); err != nil {
79-
return fmt.Errorf("%s %s response decoding: %v", method, endpoint, err)
80+
return fmt.Errorf("%s %s response decoding: %w", method, endpoint, err)
8081
}
8182
}
8283

pkg/platformclient/collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (c *HTTPClient) PromoteCollector(appID string, specID string, channelIDs ..
1414
ChannelIDs: channelIDs,
1515
}
1616
if err := c.DoJSON("POST", path, http.StatusOK, body, nil); err != nil {
17-
return fmt.Errorf("PromoteCollector: %v", err)
17+
return fmt.Errorf("PromoteCollector: %w", err)
1818
}
1919
return nil
2020
}

pkg/platformclient/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
)
99

10-
// ErrNotFound represnets a 404 response from the API.
10+
// ErrNotFound represents a 404 response from the API.
1111
var ErrNotFound = errors.New("Not found")
1212

1313
// BadRequest represents a 400 response from the API.

pkg/platformclient/license.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func (c *HTTPClient) CreateLicense(license *v2.LicenseV2) (*v2.LicenseV2, error) {
1212
created := &v2.LicenseV2{}
1313
if err := c.DoJSON("POST", "/v2/license", http.StatusCreated, license, created); err != nil {
14-
return nil, fmt.Errorf("CreateLicense: %v", err)
14+
return nil, fmt.Errorf("CreateLicense: %w", err)
1515
}
1616
return created, nil
1717
}

pkg/platformclient/release.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *HTTPClient) ListReleases(appID string) ([]releases.AppReleaseInfo, erro
1515
path := fmt.Sprintf("/v1/app/%s/releases", appID)
1616
releases := make([]releases.AppReleaseInfo, 0)
1717
if err := c.DoJSON("GET", path, http.StatusOK, nil, &releases); err != nil {
18-
return nil, fmt.Errorf("ListReleases: %v", err)
18+
return nil, fmt.Errorf("ListReleases: %w", err)
1919
}
2020
return releases, nil
2121
}
@@ -28,12 +28,12 @@ func (c *HTTPClient) CreateRelease(appID string, yaml string) (*releases.AppRele
2828
}
2929
release := &releases.AppReleaseInfo{}
3030
if err := c.DoJSON("POST", path, http.StatusCreated, body, release); err != nil {
31-
return nil, fmt.Errorf("CreateRelease: %v", err)
31+
return nil, fmt.Errorf("CreateRelease: %w", err)
3232
}
3333
// API does not accept yaml in create operation, so first create then udpate
3434
if yaml != "" {
3535
if err := c.UpdateRelease(appID, release.Sequence, yaml); err != nil {
36-
return nil, fmt.Errorf("CreateRelease with YAML: %v", err)
36+
return nil, fmt.Errorf("CreateRelease with YAML: %w", err)
3737
}
3838
}
3939
return release, nil
@@ -50,7 +50,7 @@ func (c *HTTPClient) UpdateRelease(appID string, sequence int64, yaml string) er
5050
req.Header.Set("Content-Type", "application/yaml")
5151
resp, err := http.DefaultClient.Do(req)
5252
if err != nil {
53-
return fmt.Errorf("UpdateRelease: %v", err)
53+
return fmt.Errorf("UpdateRelease: %w", err)
5454
}
5555
defer resp.Body.Close()
5656
if resp.StatusCode != http.StatusOK {
@@ -67,7 +67,7 @@ func (c *HTTPClient) GetRelease(appID string, sequence int64) (*releases.AppRele
6767
path := fmt.Sprintf("/v1/app/%s/%d/properties", appID, sequence)
6868
release := &releases.AppRelease{}
6969
if err := c.DoJSON("GET", path, http.StatusOK, nil, release); err != nil {
70-
return nil, fmt.Errorf("GetRelease: %v", err)
70+
return nil, fmt.Errorf("GetRelease: %w", err)
7171
}
7272
return release, nil
7373
}
@@ -82,7 +82,7 @@ func (c *HTTPClient) PromoteRelease(appID string, sequence int64, label, notes s
8282
Channels: channelIDs,
8383
}
8484
if err := c.DoJSON("POST", path, http.StatusNoContent, body, nil); err != nil {
85-
return fmt.Errorf("PromoteRelease: %v", err)
85+
return fmt.Errorf("PromoteRelease: %w", err)
8686
}
8787
return nil
8888
}

0 commit comments

Comments
 (0)