Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/goalstate/goalstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/instanceview/instanceview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/types/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down