diff --git a/internal/goalstate/goalstate.go b/internal/goalstate/goalstate.go index 8d592bd..e46154a 100644 --- a/internal/goalstate/goalstate.go +++ b/internal/goalstate/goalstate.go @@ -109,7 +109,7 @@ func startAsync(ctx *log.Context, setting settings.SettingsCommon, notifier *obs } // Overwrite function to report status to HGAP. This function prepares the status to be sent to the HGAP and then calls the notifier to send it. - cmd.Functions.ReportStatus = func(ctx *log.Context, _ types.HandlerEnvironment, metadata types.RCMetadata, statusType types.StatusType, c types.Cmd, msg string) error { + cmd.Functions.ReportStatus = func(ctx *log.Context, _ types.HandlerEnvironment, metadata types.RCMetadata, statusType types.StatusType, c types.Cmd, msg string, exitcode ...int) error { if !c.ShouldReportStatus { ctx.Log("status", fmt.Sprintf("status not reported for operation %v (by design)", c.Name)) return nil diff --git a/internal/instanceview/instanceview.go b/internal/instanceview/instanceview.go index d1a0542..773bf53 100755 --- a/internal/instanceview/instanceview.go +++ b/internal/instanceview/instanceview.go @@ -26,8 +26,9 @@ func ReportInstanceView(ctx *log.Context, hEnv types.HandlerEnvironment, metadat if c.Functions.ErrorReport == nil { return c.Functions.ReportStatus(ctx, hEnv, metadata, t, c, msg) } - - return c.Functions.ErrorReport(ctx, hEnv, metadata, t, c, msg, instanceview.ExitCode) + slice := []int{instanceview.ExitCode} + return c.Functions.ReportStatus(ctx, hEnv, metadata, t, c, msg, slice...) + // return c.Functions.ErrorReport(ctx, hEnv, metadata, t, c, msg, instanceview.ExitCode) } func SerializeInstanceView(instanceview *types.RunCommandInstanceView) (string, error) { diff --git a/internal/status/status.go b/internal/status/status.go index e60f17b..9318d25 100755 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -22,13 +22,18 @@ var immediateGSInTerminalStatusLock = sync.Mutex{} // If an error occurs reporting the status, it will be logged and returned. // // This function is used by default for reporting status to the local file system unless a different method is specified. -func ReportStatusToLocalFile(ctx *log.Context, hEnv types.HandlerEnvironment, metadata types.RCMetadata, statusType types.StatusType, c types.Cmd, msg string) error { +func ReportStatusToLocalFile(ctx *log.Context, hEnv types.HandlerEnvironment, metadata types.RCMetadata, statusType types.StatusType, c types.Cmd, msg string, exitcode ...int) error { if !c.ShouldReportStatus { ctx.Log("status", "not reported for operation (by design)") return nil } rootStatusJson, err := getRootStatusJson(ctx, statusType, c, msg, true, metadata.ExtName) + if c.Functions.ErrorReport != nil { + var errorcode = constants.TranslateExitCodeToErrorClarification(exitcode[0]) + rootStatusJson, err = getRootStatusJsonWithErrorClarification(ctx, statusType, c, msg, true, metadata.ExtName, errorcode) + } + if err != nil { return errors.Wrap(err, "failed to get json for status report") } @@ -50,7 +55,7 @@ func ReportStatusToLocalFileWithErrorClarification(ctx *log.Context, hEnv types. return nil } var errorcode = constants.TranslateExitCodeToErrorClarification(exitcode) - rootStatusJson, err := getRootStatusJsonWithErrorCalrification(ctx, statusType, c, msg, true, metadata.ExtName, errorcode) + rootStatusJson, err := getRootStatusJsonWithErrorClarification(ctx, statusType, c, msg, true, metadata.ExtName, errorcode) if err != nil { return errors.Wrap(err, "failed to get json for status report") } @@ -222,7 +227,7 @@ func getRootStatusJson(ctx *log.Context, statusType types.StatusType, c types.Cm return b, nil } -func getRootStatusJsonWithErrorCalrification(ctx *log.Context, statusType types.StatusType, c types.Cmd, msg string, indent bool, extName string, errorcode int) ([]byte, error) { +func getRootStatusJsonWithErrorClarification(ctx *log.Context, statusType types.StatusType, c types.Cmd, msg string, indent bool, extName string, errorcode int) ([]byte, error) { ctx.Log("message", "creating json to report status") statusReport := types.NewStatusReportWithErrorClarification(statusType, c.Name, msg, extName, errorcode) diff --git a/internal/types/commands.go b/internal/types/commands.go index efaf4bf..892ac54 100755 --- a/internal/types/commands.go +++ b/internal/types/commands.go @@ -5,7 +5,7 @@ import ( ) type cmdFunc func(ctx *log.Context, hEnv HandlerEnvironment, report *RunCommandInstanceView, metadata RCMetadata, c Cmd) (stdout string, stderr string, err error, exitCode int) -type reportStatusFunc func(ctx *log.Context, hEnv HandlerEnvironment, metadata RCMetadata, statusType StatusType, c Cmd, msg string) error +type reportStatusFunc func(ctx *log.Context, hEnv HandlerEnvironment, metadata RCMetadata, statusType StatusType, c Cmd, msg string, exitcode ...int) error type preFunc func(ctx *log.Context, hEnv HandlerEnvironment, metadata RCMetadata, c Cmd) error type cleanupFunc func(ctx *log.Context, metadata RCMetadata, h HandlerEnvironment, runAsUser string) type reportErrorClarificationFunc func(ctx *log.Context, hEnv HandlerEnvironment, metadata RCMetadata, statusType StatusType, c Cmd, msg string, exitcode int) error