Skip to content

T feyiadeaga error clarification#55

Merged
FeyiAdeaga merged 27 commits into
Azure:dev/t-feadeaga_error_changesfrom
FeyiAdeaga:t-feyiadeaga_error_clarification
Aug 8, 2025
Merged

T feyiadeaga error clarification#55
FeyiAdeaga merged 27 commits into
Azure:dev/t-feadeaga_error_changesfrom
FeyiAdeaga:t-feyiadeaga_error_clarification

Conversation

@FeyiAdeaga

Copy link
Copy Markdown

Adding ErrorClarification for RunCommandV2 on linux

@FeyiAdeaga FeyiAdeaga marked this pull request as draft June 30, 2025 22:05
@FeyiAdeaga

Copy link
Copy Markdown
Author

I decided to get log errors in this PR by using the existing exitcodes and converting them to corresponding errors that are added to the status report object that is reported.

Comment thread internal/types/commands.go Outdated
Comment thread internal/instanceview/instanceview.go Outdated
case ExitCode_Okay:
return 0 // Success, no error clarification needed

// User errors (-100s) -> map to positive user error codes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this mapping for user errors. Directly change ExitCode_* to new positive number for user errors as expected by CRP. Linux returns positive error codes. Please also check what other Linux extensions are doing like CustomScript

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. In RunCommand V2 Windows we just return the error clarification as an int for the exit code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in the case of the implementation here it would be the opposite.

case ExitCode_RunAsLookupUserFailed:
return CommandExecution_RunAsUserLogonFailed

// Service errors (-200s) -> map based on specific failure type

@viveklingaiah viveklingaiah Jul 23, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. no mapping needed. You can directly use the negative code for service errors. Does CRP expect negative service code for service error ?

Comment thread internal/status/immediatestatus.go Outdated
Comment thread internal/types/status.go
Comment thread internal/types/status.go
Comment thread internal/types/status.go
Comment thread internal/status/immediatestatus.go Outdated
Comment thread internal/status/immediatestatus.go Outdated
Comment thread internal/status/status.go
Comment thread internal/status/status.go Outdated
Comment thread internal/types/status.go Outdated
Comment thread internal/types/status.go Outdated
@FeyiAdeaga FeyiAdeaga marked this pull request as ready for review July 29, 2025 17:01

// 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exitCode is unused?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is optional. In the use case only enable functions pass the value

Comment thread internal/status/status.go
//
// 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the exitcode ...int a hack around go not allowing polymorphism of functions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it to pass an optional parameter to the already existing function

case ExitCode_Okay:
return 0 // Success, no error clarification needed

// User errors (-100s) -> map to positive user error codes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. In RunCommand V2 Windows we just return the error clarification as an int for the exit code.

"testing"
)

func TestTranslateExitCodeToErrorClarification(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just convert the error clarification to an int, then we don't need this test.
We should also try to repro each condition in a test case, since this improves the overall quality of the extension.

goalStateKey := key.(types.GoalStateKey)
if goalStateKey.RuntimeSettingsState != "disabled" {
if value.(types.StatusItem) != (types.StatusItem{}) {
if !IsEmptyStatusItem(value.(types.StatusItem)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not following why this is necessary. Please at least add a comment stating why we need the DeepEqual call.

case ExitCode_Okay:
return 0 // Success, no error clarification needed

// User errors (-100s) -> map to positive user error codes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in the case of the implementation here it would be the opposite.

Comment thread internal/status/status.go
return errors.Wrap(err, "failed to get json for status report")
}

ctx.Log("message", "reporting status by writing status file locally")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check whether we already have a trace stating which status we're writing. If not, then this trace should provide the status and error clarification too.

Comment thread internal/status/status.go
}
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe elsewhere in the code we also write status, so this would overwrite it.

@FeyiAdeaga FeyiAdeaga changed the base branch from main to dev/t-feadeaga_error_changes August 8, 2025 21:54
@FeyiAdeaga FeyiAdeaga merged commit 3c5c8c0 into Azure:dev/t-feadeaga_error_changes Aug 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants