From 9f7ffea6c72063a4b7606b0bed24f59faea734f7 Mon Sep 17 00:00:00 2001 From: Jenson Date: Tue, 12 Feb 2019 12:46:49 +0530 Subject: [PATCH] [Jenson|Aishwarya] fix job execution error handling --- cmd/execution/executioner.go | 6 +++--- cmd/execution/executioner_test.go | 3 ++- cmd/version/version.go | 2 +- daemon/client.go | 7 +++++-- proctord/utility/utils.go | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/execution/executioner.go b/cmd/execution/executioner.go index 1772d1fb..09ba0863 100644 --- a/cmd/execution/executioner.go +++ b/cmd/execution/executioner.go @@ -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 { diff --git a/cmd/execution/executioner_test.go b/cmd/execution/executioner_test.go index 14d1cd17..fee4cdda 100644 --- a/cmd/execution/executioner_test.go +++ b/cmd/execution/executioner_test.go @@ -3,6 +3,7 @@ package execution import ( "errors" "fmt" + "github.com/stretchr/testify/mock" "testing" "github.com/fatih/color" @@ -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) diff --git a/cmd/version/version.go b/cmd/version/version.go index 79e53598..fd6474cb 100644 --- a/cmd/version/version.go +++ b/cmd/version/version.go @@ -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{ diff --git a/daemon/client.go b/daemon/client.go index 08e29a47..169151e0 100644 --- a/daemon/client.go +++ b/daemon/client.go @@ -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) } @@ -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)) } diff --git a/proctord/utility/utils.go b/proctord/utility/utils.go index 58d8d0e3..9a8613ab 100644 --- a/proctord/utility/utils.go +++ b/proctord/utility/utils.go @@ -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!!!"