Skip to content

Commit

Permalink
[Jenson|Aishwarya] fix job execution error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jensoncs committed Feb 12, 2019
1 parent 95f39d3 commit 9f7ffea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cmd/execution/executioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func NewCmd(printer io.Printer, proctorDClient daemon.Client, osExitFunc func(in

executedProcName, err := proctorDClient.ExecuteProc(procName, procArgs)
if err != nil {
printer.Println("Error submitting proc for execution", color.FgRed)
osExitFunc(1)
printer.Println(err.Error(), color.FgRed)
print()
return
}

printer.Println("Proc submitted for execution. \nStreaming logs:", color.FgGreen)
err = proctorDClient.StreamProcLogs(executedProcName)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/execution/executioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package execution
import (
"errors"
"fmt"
"github.com/stretchr/testify/mock"
"testing"

"github.com/fatih/color"
Expand Down Expand Up @@ -120,7 +121,7 @@ func (s *ExecutionCmdTestSuite) TestExecutionCmdForProctorDExecutionFailure() {
procArgs := make(map[string]string)
s.mockProctorDClient.On("ExecuteProc", "say-hello-world", procArgs).Return("", errors.New("test error")).Once()

s.mockPrinter.On("Println", "Error submitting proc for execution", color.FgRed).Once()
s.mockPrinter.On("Println", mock.Anything, color.FgRed).Once()

osExitFunc := func(exitCode int) {
assert.Equal(s.T(), 1, exitCode)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

const ClientVersion = "v0.5.0"
const ClientVersion = "v0.6.0"

func NewCmd(printer io.Printer) *cobra.Command {
return &cobra.Command{
Expand Down
7 changes: 5 additions & 2 deletions daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func (c *client) ExecuteProc(name string, args map[string]string) (string, error
req.Header.Add(utility.AccessTokenHeaderKey, c.accessToken)
req.Header.Add(utility.ClientVersionHeaderKey, c.clientVersion)
resp, err := client.Do(req)

if err != nil {
return "", buildNetworkError(err)
}
Expand Down Expand Up @@ -415,7 +414,11 @@ func buildHTTPError(c *client, resp *http.Response) error {
if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf(utility.JobNotFoundError)
}


if resp.StatusCode == http.StatusForbidden {
return fmt.Errorf(utility.JobForbiddenErrorHeader)
}

return fmt.Errorf("%s\nStatus Code: %d, %s", utility.GenericResponseErrorHeader, resp.StatusCode, http.StatusText(resp.StatusCode))
}

Expand Down
1 change: 1 addition & 0 deletions proctord/utility/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const UnauthorizedErrorInvalidConfig = "Please check the EMAIL_ID and ACCESS_TOK
const GenericListCmdError = "Error fetching list of procs. Please check configuration and network connectivity"
const GenericProcCmdError = "Error executing proc. Please check configuration and network connectivity"
const GenericDescribeCmdError = "Error fetching description of proc. Please check configuration and network connectivity"
const JobForbiddenErrorHeader = "Access Denied : You are Not Authorized to Perform this action."

const UnauthorizedErrorHeader = "Unauthorized Access!!!"
const GenericTimeoutErrorHeader = "Connection Timeout!!!"
Expand Down

0 comments on commit 9f7ffea

Please sign in to comment.