Skip to content

Commit ac67e9d

Browse files
committed
Checkpoint - updating RCV2 for user errors
1 parent 3c5c8c0 commit ac67e9d

15 files changed

Lines changed: 129 additions & 510 deletions

File tree

internal/cmds/cmds.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func install(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComm
133133
if err := os.MkdirAll(DataDir, 0755); err != nil {
134134
errMessage := fmt.Sprintf("Failed to create data dir: %v due to: %v", DataDir, err)
135135
extensionEvents.LogErrorEvent("install", errMessage)
136-
return "", "", errors.Wrap(err, errMessage), constants.ExitCode_CreateDataDirectoryFailed
136+
return "", "", errors.Wrap(err, errMessage), constants.FileSystem_CreateDataDirectoryFailed
137137
}
138138

139139
ctx.Log("event", "created data dir", "path", DataDir)
@@ -155,7 +155,7 @@ func uninstall(ctx *log.Context, h types.HandlerEnvironment, report *types.RunCo
155155
if err := os.RemoveAll(DataDir); err != nil {
156156
errMessage := fmt.Sprintf("Failed to delete data directory: %v due to: %v", DataDir, err)
157157
extensionEvents.LogErrorEvent("uninstall", errMessage)
158-
return "", "", errors.Wrap(err, errMessage), constants.ExitCode_RemoveDataDirectoryFailed
158+
return "", "", errors.Wrap(err, errMessage), constants.FileSystem_RemoveDataDirectoryFailed
159159
}
160160
ctx.Log("event", "removed data dir")
161161
extensionEvents.LogInformationalEvent("uninstall", fmt.Sprintf("removed data dir %v", DataDir))
@@ -190,7 +190,7 @@ func enable(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComma
190190
if err1 != nil {
191191
errMessage := fmt.Sprintf("Failed to get configuration: %v", err1)
192192
extensionEvents.LogErrorEvent("enable", errMessage)
193-
return "", "", errors.Wrap(err1, "failed to get configuration"), constants.ExitCode_GetHandlerSettingsFailed
193+
return "", "", err1, constants.CommandExecution_BadConfig
194194
}
195195

196196
exitCode, err := immediatecmds.Enable(ctx, h, metadata.ExtName, metadata.SeqNum, cfg, extensionEvents)
@@ -208,7 +208,7 @@ func enable(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComma
208208
return "",
209209
"",
210210
errors.Wrap(err, fmt.Sprintf("File downloads failed. Use either a public script URI that points to .sh file, Azure storage blob SAS URI or storage blob accessible by a managed identity and retry. If managed identity is used, make sure it has been given access to container of storage blob '%s' with 'Storage Blob Data Reader' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info, refer https://aka.ms/RunCommandManagedLinux", download.GetUriForLogging(cfg.ScriptURI()))),
211-
constants.ExitCode_ScriptBlobDownloadFailed
211+
constants.FileDownload_GenericError
212212
}
213213

214214
err = downloadArtifacts(ctx, dir, &cfg)
@@ -217,7 +217,7 @@ func enable(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComma
217217
extensionEvents.LogErrorEvent("enable", errMessage)
218218
return "", "",
219219
errors.Wrap(err, "Artifact downloads failed. Use either a public artifact URI that points to .sh file, Azure storage blob SAS URI, or storage blob accessible by a managed identity and retry."),
220-
constants.ExitCode_DownloadArtifactFailed
220+
constants.ArtifactDownload_GenericError
221221
}
222222

223223
blobCreateOrReplaceError := "Error creating AppendBlob '%s' using SAS token or Managed identity. Please use a valid blob SAS URI with [read, append, create, write] permissions OR managed identity. If managed identity is used, make sure Azure blob and identity exist, and identity has been given access to storage blob's container with 'Storage Blob Data Contributor' role assignment. In case of user-assigned identity, make sure you add it under VM's identity and provide outputBlobUri / errorBlobUri and corresponding clientId in outputBlobManagedIdentity / errorBlobManagedIdentity parameter(s). In case of system-assigned identity, do not use outputBlobManagedIdentity / errorBlobManagedIdentity parameter(s). For more info, refer https://aka.ms/RunCommandManagedLinux"
@@ -236,7 +236,7 @@ func enable(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComma
236236
return "",
237237
"",
238238
errors.Wrap(outputBlobAppendCreateOrReplaceError, fmt.Sprintf(blobCreateOrReplaceError, cfg.OutputBlobURI)),
239-
constants.ExitCode_BlobCreateOrReplaceFailed
239+
constants.AppendBlobCreation_Other
240240
}
241241
}
242242

@@ -254,7 +254,7 @@ func enable(ctx *log.Context, h types.HandlerEnvironment, report *types.RunComma
254254
return "",
255255
"",
256256
errors.Wrap(errorBlobAppendCreateOrReplaceError, fmt.Sprintf(blobCreateOrReplaceError, cfg.ErrorBlobURI)),
257-
constants.ExitCode_BlobCreateOrReplaceFailed
257+
constants.AppendBlobCreation_Other
258258
}
259259
}
260260

@@ -849,7 +849,7 @@ func runCmd(ctx *log.Context, dir string, scriptFilePath string, cfg *handlerset
849849
err := files.SaveScriptFile(scriptFilePath, cfg.Script())
850850
if err != nil {
851851
ctx.Log("event", "failed to save script to file", "error", err, "file", scriptFilePath)
852-
return errors.Wrap(err, "failed to save script to file"), constants.ExitCode_SaveScriptFailed
852+
return errors.Wrap(err, "failed to save script to file"), constants.FileDownload_UnableToWriteFile
853853
}
854854
} else if cfg.ScriptURI() != "" {
855855
// If scriptUri is specified then cmd should start it
Lines changed: 45 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
package constants
22

33
const (
4-
FileDownload_BadRequest = -41
5-
FileDownload_UnknownError = -40
6-
FileDownload_StorageError = -42
7-
FileDownload_UnhandledError = -43
4+
FileDownload_BadRequest = -41
5+
FileDownload_UnknownError = -40
6+
FileDownload_StorageError = -42
7+
FileDownload_UnhandledError = -43
8+
FileDownload_StorageClientInitialization = -44
89

9-
Internal_CouldNotFindCertificate = -20
10-
Internal_CouldNotDecrypt = -22
11-
Internal_ArtifactCountMismatch = -23
12-
Internal_ArtifactDoesNotExist = -24
10+
Internal_CouldNotFindCertificate = -20
11+
Internal_CouldNotDecrypt = -22
12+
Internal_ArtifactCountMismatch = -23
13+
Internal_ArtifactDoesNotExist = -24
14+
Internal_IncorrectRunAsScriptPath = -25
15+
Internal_RunAsOpenSourceScriptFileFailed = -26
16+
Internal_RunAsCreateRunAsScriptFileFailed = -27
17+
Internal_RunAsCopySourceScriptToRunAsScriptFileFailed = -28
18+
Internal_RunAsLookupUserUidFailed = -29
19+
Internal_RunAsScriptFileChangeOwnerFailed = -30
20+
Internal_RunAsScriptFileChangePermissionsFailed = -31
21+
22+
Internal_CouldNotParseSettings = -32
23+
Internal_InvalidHandlerSettingsJson = -33
24+
Internal_InvalidHandlerSettingsCount = -34
25+
Internal_NoHandlerSettingsThumbprint = -35
26+
Internal_HandlerSettingsFailedToDecode = -36
27+
Internal_DecryptingProtectedSettingsFailed = -37
28+
Internal_UnmarshalProtectedSettingsFailed = -38
29+
Internal_UnmarshalSettingsFailed = -39
1330

1431
SystemError = -1 // CRP will interpret anything > 0 as a user error
1532

@@ -23,12 +40,21 @@ const (
2340
CustomerInput_StorageCredsAndMIBothSpecified = 26
2441
CustomerInput_ClientIdObjectIdBothSpecified = 27
2542
CustomerInput_ErrorAndOutputBlobsSame = 28
43+
CustomerInput_NoScriptSpecified = 29
2644

27-
FileDownload_AccessDenied = 52
28-
FileDownload_DoesNotExist = 53
29-
FileDownload_NetworkingError = 54
30-
FileDownload_GenericError = 55
31-
FileDownload_UnableToWriteFile = 57
45+
FileDownload_AccessDenied = 52
46+
FileDownload_DoesNotExist = 53
47+
FileDownload_NetworkingError = 54
48+
FileDownload_GenericError = 55
49+
FileDownload_UnableToWriteFile = 57
50+
ArtifactDownload_GenericError = 58
51+
FileDownload_UnableToParseFileName = 59
52+
FileDownload_CannotExtractFileNameFromUrl = 60
53+
FileDownload_InvalidFileName = 61
54+
FileDownload_FailedStatusCode = 62
55+
FileDownload_CannotParseUrl = 63
56+
FileDownload_CannotGenerateSasKey = 64
57+
FileDownload_Empty = 65
3258

3359
Msi_NotFound = 70
3460
Msi_DoesNotHaveRightPermissions = 71
@@ -45,89 +71,10 @@ const (
4571
ImmediateRC_TaskTimeout = 102
4672
ImmediateRC_UnknownFailure = 103
4773
ImmediateRC_UnhandledException = 104
48-
)
49-
50-
func TranslateExitCodeToErrorClarification(exitCode int) int {
51-
switch exitCode {
52-
case ExitCode_Okay:
53-
return 0 // Success, no error clarification needed
74+
ImmediateRC_CommandSkipped = 105
5475

55-
// User errors (-100s) -> map to positive user error codes
56-
case ExitCode_ScriptBlobDownloadFailed:
57-
return FileDownload_GenericError
58-
case ExitCode_BlobCreateOrReplaceFailed:
59-
return AppendBlobCreation_Other
60-
case ExitCode_RunAsLookupUserFailed:
61-
return CommandExecution_RunAsUserLogonFailed
62-
63-
// Service errors (-200s) -> map based on specific failure type
64-
case ExitCode_CreateDataDirectoryFailed, ExitCode_RemoveDataDirectoryFailed:
65-
return SystemError // File system operation failures
66-
case ExitCode_GetHandlerSettingsFailed:
67-
return CommandExecution_BadConfig
68-
case ExitCode_SaveScriptFailed:
69-
return FileDownload_UnableToWriteFile
70-
case ExitCode_CommandExecutionFailed:
71-
return CommandExecution_FailureExitCode
72-
case ExitCode_OpenStdOutFileFailed, ExitCode_OpenStdErrFileFailed:
73-
return SystemError // I/O failures
74-
case ExitCode_IncorrectRunAsScriptPath, ExitCode_RunAsIncorrectScriptPath:
75-
return CommandExecution_BadConfig
76-
case ExitCode_RunAsOpenSourceScriptFileFailed:
77-
return FileDownload_DoesNotExist
78-
case ExitCode_RunAsCreateRunAsScriptFileFailed, ExitCode_RunAsCopySourceScriptToRunAsScriptFileFailed:
79-
return FileDownload_UnableToWriteFile
80-
case ExitCode_RunAsLookupUserUidFailed:
81-
return CommandExecution_RunAsUserLogonFailed
82-
case ExitCode_RunAsScriptFileChangeOwnerFailed, ExitCode_RunAsScriptFileChangePermissionsFailed:
83-
return SystemError // Permission/ownership failures
84-
case ExitCode_DownloadArtifactFailed:
85-
return FileDownload_GenericError
86-
case ExitCode_UpgradeInstalledServiceFailed, ExitCode_InstallServiceFailed,
87-
ExitCode_UninstallInstalledServiceFailed, ExitCode_DisableInstalledServiceFailed:
88-
return SystemError // Service management failures
89-
case ExitCode_CopyStateForUpdateFailed:
90-
return FileDownload_UnableToWriteFile
91-
case ExitCode_SkippedImmediateGoalState:
92-
return ImmediateRC_TaskCanceled
93-
case ExitCode_ImmediateTaskTimeout:
94-
return ImmediateRC_TaskTimeout
95-
case ExitCode_ImmediateTaskFailed:
96-
return ImmediateRC_UnknownFailure
97-
98-
// Handle standard Linux exit codes
99-
default:
100-
switch {
101-
case exitCode == 0:
102-
return 0 // Success
103-
case exitCode > 0 && exitCode < 128:
104-
// Standard program exit codes (1-127)
105-
if exitCode == 1 {
106-
return CommandExecution_FailureExitCode
107-
} else if exitCode == 126 {
108-
return CommandExecution_RunAsCreateProcessFailed // Command not executable
109-
} else if exitCode == 127 {
110-
return FileDownload_DoesNotExist // Command not found
111-
} else {
112-
return CommandExecution_FailureExitCode
113-
}
114-
case exitCode >= 128 && exitCode <= 255:
115-
// Signal-terminated processes (128 + signal number)
116-
if exitCode == 130 { // SIGINT (Ctrl+C)
117-
return ImmediateRC_TaskCanceled
118-
} else if exitCode == 137 { // SIGKILL
119-
return ImmediateRC_TaskTimeout
120-
} else if exitCode == 143 { // SIGTERM
121-
return ImmediateRC_TaskCanceled
122-
} else {
123-
return ImmediateRC_UnhandledException
124-
}
125-
case exitCode < 0:
126-
// Negative exit codes - internal errors
127-
return SystemError
128-
default:
129-
// Unknown exit codes
130-
return ImmediateRC_UnknownFailure
131-
}
132-
}
133-
}
76+
FileSystem_CreateDataDirectoryFailed = 110
77+
FileSystem_RemoveDataDirectoryFailed = 121
78+
FileSystem_OpenStandardOutFailed = 122
79+
FileSystem_OpenStandardErrorFailed = 123
80+
)

0 commit comments

Comments
 (0)