Skip to content

Commit 3af2b76

Browse files
author
Oleg Sucharevich
committed
dont panic but exit on some errors
1 parent c95a04e commit 3af2b76

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

cmd/get_pipeline.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package cmd
1616

1717
import (
18+
"fmt"
19+
1820
"github.com/codefresh-io/go-sdk/internal"
1921
"github.com/codefresh-io/go-sdk/pkg/codefresh"
2022
humanize "github.com/dustin/go-humanize"
@@ -32,7 +34,7 @@ var getPipelineCmd = &cobra.Command{
3234
client := viper.Get("codefresh")
3335
codefreshClient, ok := client.(codefresh.Codefresh)
3436
if !ok {
35-
panic("Faild to create Codefresh cleint")
37+
internal.DieOnError(fmt.Errorf("Faild to create Codefresh client"))
3638
}
3739
table := internal.CreateTable()
3840
table.SetHeader([]string{"Pipeline Name", "Created At", "Updated At"})

pkg/codefresh/codefresh.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package codefresh
22

33
import (
44
"fmt"
5+
"net/url"
6+
7+
"github.com/codefresh-io/go-sdk/internal"
58

69
"gopkg.in/h2non/gentleman.v2"
710
"gopkg.in/h2non/gentleman.v2/plugins/body"
@@ -28,7 +31,9 @@ func New(opt *ClietOptions) Codefresh {
2831

2932
func (c *codefresh) requestAPI(opt *requestOptions) (*gentleman.Response, error) {
3033
req := c.client.Request()
31-
req.Path(opt.path)
34+
url, err := url.Parse(opt.path)
35+
internal.DieOnError(err)
36+
req.Path(url.String())
3237
req.Method(opt.method)
3338
req.AddHeader("Authorization", c.token)
3439
if opt.body != nil {

pkg/utils/utils.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package utils
22

33
import (
4+
"fmt"
5+
6+
"github.com/codefresh-io/go-sdk/internal"
47
"github.com/codefresh-io/go-sdk/pkg/codefresh"
58
)
69

710
func CastToCodefreshOrDie(candidate interface{}) codefresh.Codefresh {
811
client, ok := candidate.(codefresh.Codefresh)
912
if !ok {
10-
panic("Failed to cast candidate to Codefresh client")
13+
internal.DieOnError(fmt.Errorf("Failed to cast candidate to Codefresh client"))
1114
}
1215
return client
1316
}

0 commit comments

Comments
 (0)