Skip to content

Commit 7fe30e5

Browse files
author
Max Siegieda
authored
Merge pull request #21 from ReconfigureIO/fix/deployment-not-found-error
interpret the error returned from request.go
2 parents 081740c + 9f7dee7 commit 7fe30e5

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var (
5151
errProjectNotCreated = errors.New("No projects found. Run 'reco project create' to create one")
5252
errProjectNotFound = errors.New("Project not found. Run 'reco project list' to view all your available projects")
5353
errNetworkError = errors.New("Network error")
54-
errNotFound = errors.New("Not found")
54+
ErrNotFound = errors.New("Not found")
5555
errInvalidToken = errors.New("The token is invalid")
5656
errUnknownError = errors.New("Unknown error occurred")
5757
errBadResponse = errors.New("Bad response from server")

cmd/deployment.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"reflect"
@@ -17,6 +18,8 @@ var (
1718
wait: "true",
1819
}
1920

21+
errorDeploymentNotFound = errors.New("No deployment with that ID could be found. Run 'reco deploy list' to view available deployments")
22+
2023
deploymentCmdStart = &cobra.Command{
2124
Use: "run [flags] <build_ID> <your_cmd> -- [args]",
2225
Aliases: []string{"r", "start", "starts"},
@@ -64,7 +67,7 @@ your command. The two forms are equivalent:
6467
Run: func(cmd *cobra.Command, args []string) {
6568
l := reflect.ValueOf(tool).MethodByName("Deployment").Call(nil)[0].Interface()
6669
if err := l.(reco.Job).Log(args[0], os.Stdout); err != nil {
67-
exitWithError(err)
70+
exitWithError(interpretErrorDeployment(err))
6871
}
6972
},
7073
}
@@ -84,7 +87,7 @@ your command. The two forms are equivalent:
8487
Run: func(cmd *cobra.Command, args []string) {
8588
l := reflect.ValueOf(tool).MethodByName("Deployment").Call(nil)[0].Interface()
8689
if err := l.(reco.Job).Stop(args[0]); err != nil {
87-
exitWithError(err)
90+
exitWithError(interpretErrorDeployment(err))
8891
}
8992
logger.Std.Printf("deployment stopped successfully")
9093
},
@@ -125,7 +128,7 @@ func startDeployment(cmd *cobra.Command, args []string) {
125128
}
126129
out, err := tool.Deployment().Start(reco.Args{image, command, commandArgs, deploymentVars.wait})
127130
if err != nil {
128-
exitWithError(err)
131+
exitWithError(interpretErrorDeployment(err))
129132
}
130133
logger.Std.Println(out)
131134
}
@@ -135,6 +138,15 @@ func connectDeployment(cmd *cobra.Command, args []string) {
135138
exitWithError("deployment ID required")
136139
}
137140
if err := tool.Deployment().(reco.DeploymentProxy).Connect(args[0], true); err != nil {
138-
exitWithError(err)
141+
exitWithError(interpretErrorDeployment(err))
142+
}
143+
}
144+
145+
func interpretErrorDeployment(err error) error {
146+
switch err {
147+
case reco.ErrNotFound:
148+
return errorDeploymentNotFound
149+
default:
150+
return err
139151
}
140152
}

cmd/graph.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/ReconfigureIO/reco/logger"
1111
)
1212

13+
var errorGraphNotFound = errors.New("No graph with that ID could be found. Run 'reco graph list' to view available graphs")
14+
1315
var graphCmd = &cobra.Command{
1416
Use: "graph",
1517
Aliases: []string{"g", "graphs"},
@@ -61,7 +63,7 @@ func generateGraph(cmd *cobra.Command, args []string) {
6163
}
6264
id, err := tool.Graph().Generate(reco.Args{srcDir})
6365
if err != nil {
64-
exitWithError(err)
66+
exitWithError(interpretErrorGraph(err))
6567
}
6668
logger.Std.Println("Graph submitted. Run 'reco graph list' to track the status of your graph")
6769
logger.Std.Println("Once the graph has been completed run 'reco graph open " + id + "' to view it")
@@ -73,7 +75,7 @@ func openGraph(_ *cobra.Command, args []string) {
7375
}
7476
file, err := tool.Graph().Open(args[0])
7577
if err != nil {
76-
exitWithError(err)
78+
exitWithError(interpretErrorGraph(err))
7779
}
7880
var cmd *exec.Cmd
7981
switch runtime.GOOS {
@@ -94,10 +96,19 @@ func openGraph(_ *cobra.Command, args []string) {
9496
}
9597
}
9698

99+
func interpretErrorGraph(err error) error {
100+
switch err {
101+
case reco.ErrNotFound:
102+
return errorGraphNotFound
103+
default:
104+
return err
105+
}
106+
}
107+
97108
func validGraphDir(srcDir string) bool {
98109
// Do we have a main.go to graph?
99110
if !hasMain(srcDir) {
100111
return false
101112
}
102113
return true
103-
}
114+
}

deployment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (p deploymentJob) List(filter M) (printer.Table, error) {
120120
}
121121

122122
table = printer.Table{
123-
Header: []string{"id", "image", "command", "status", "started", "duration"},
123+
Header: []string{"deployment id", "build id", "command", "status", "started", "duration"},
124124
Body: body,
125125
}
126126
if allProjects {

request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (p *clientRequest) Do(method string, body interface{}) (*http.Response, err
139139
case 401, 403:
140140
err = errAuthFailed
141141
case 404:
142-
err = errNotFound
142+
err = ErrNotFound
143143
}
144144
} else if err != nil {
145145
err = errNetworkError

0 commit comments

Comments
 (0)