From d586edb5a73ea86398a344f6e98c497281b7ec2c Mon Sep 17 00:00:00 2001 From: Feyi Date: Mon, 28 Jul 2025 14:59:59 -0700 Subject: [PATCH 1/3] typo --- internal/status/status.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/status/status.go b/internal/status/status.go index e60f17b..715e907 100755 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -50,7 +50,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 +222,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) From 6c028e6e5fb856df1f9c8421d97d958b75024c40 Mon Sep 17 00:00:00 2001 From: Feyi Date: Mon, 28 Jul 2025 15:08:57 -0700 Subject: [PATCH 2/3] test functionality --- internal/goalstate/goalstate.go | 2 +- internal/instanceview/instanceview.go | 8 ++++---- internal/status/status.go | 7 ++++++- internal/types/commands.go | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) 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..f66f279 100755 --- a/internal/instanceview/instanceview.go +++ b/internal/instanceview/instanceview.go @@ -23,11 +23,11 @@ func ReportInstanceView(ctx *log.Context, hEnv types.HandlerEnvironment, metadat return err } - if c.Functions.ErrorReport == nil { - return c.Functions.ReportStatus(ctx, hEnv, metadata, t, c, msg) - } + // 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) + // 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 715e907..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") } 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 From cbc7bed04c287244a2b581e33b0321f216f75b35 Mon Sep 17 00:00:00 2001 From: Feyi Date: Mon, 28 Jul 2025 15:16:31 -0700 Subject: [PATCH 3/3] test new status --- internal/instanceview/instanceview.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/instanceview/instanceview.go b/internal/instanceview/instanceview.go index f66f279..773bf53 100755 --- a/internal/instanceview/instanceview.go +++ b/internal/instanceview/instanceview.go @@ -23,10 +23,11 @@ func ReportInstanceView(ctx *log.Context, hEnv types.HandlerEnvironment, metadat return err } - // if c.Functions.ErrorReport == nil { - return c.Functions.ReportStatus(ctx, hEnv, metadata, t, c, msg) - // } - + if c.Functions.ErrorReport == nil { + return c.Functions.ReportStatus(ctx, hEnv, metadata, t, c, msg) + } + 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) }