Skip to content

Commit

Permalink
Add exit codes for errors when steampipe is running as root or in WSL1.
Browse files Browse the repository at this point in the history
Closes #3130
  • Loading branch information
pskrbasu committed Feb 21, 2023
1 parent d58f951 commit 016d373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
// postgresql engine.
func checkRoot(ctx context.Context) {
if os.Geteuid() == 0 {
exitCode = constants.ExitCodeUnknownErrorPanic
exitCode = constants.ExitCodeInvalidExecutionEnvironment
error_helpers.ShowError(ctx, fmt.Errorf(`Steampipe cannot be run as the "root" user.
To reduce security risk, use an unprivileged user account instead.`))
os.Exit(exitCode)
Expand All @@ -63,7 +63,7 @@ To reduce security risk, use an unprivileged user account instead.`))
*/

if os.Geteuid() != os.Getuid() {
exitCode = constants.ExitCodeUnknownErrorPanic
exitCode = constants.ExitCodeInvalidExecutionEnvironment
error_helpers.ShowError(ctx, fmt.Errorf("real and effective user IDs must match."))
os.Exit(exitCode)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func checkWsl1(ctx context.Context) {
return
} else {
error_helpers.ShowError(ctx, fmt.Errorf("Steampipe requires WSL2, please upgrade and try again."))
os.Exit(1)
os.Exit(constants.ExitCodeInvalidExecutionEnvironment)
}
}
}
39 changes: 20 additions & 19 deletions pkg/constants/exit_codes.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package constants

const (
ExitCodeSuccessful = 0
ExitCodeControlsAlarm = 1 // check - no runtime errors, 1 or more control alarms, no control errors
ExitCodeControlsError = 2 // check - no runtime errors, 1 or more control errors
ExitCodePluginLoadingError = 11 // plugin - loading error
ExitCodePluginListFailure = 12 // plugin - listing failed
ExitCodePluginNotFound = 13 // plugin - not found
ExitCodeSnapshotCreationFailed = 21 // snapshot - creation failed
ExitCodeSnapshotUploadFailed = 22 // snapshot - upload failed
ExitCodeServiceSetupFailure = 31 // service - setup failed
ExitCodeServiceStartupFailure = 32 // service - start failed
ExitCodeServiceStopFailure = 33 // service - stop failed
ExitCodeQueryExecutionFailed = 41 // query - 1 or more queries failed - change in behavior(previously the exitCode used to be the number of queries that failed)
ExitCodeLoginCloudConnectionFailed = 51 // login - connecting to cloud failed
ExitCodeInitializationFailed = 250 // common - initialization failed
ExitCodeBindPortUnavailable = 251 // common(service/dashboard) - port binding failed
ExitCodeNoModFile = 252 // common - no mod file
ExitCodeFileSystemAccessFailure = 253 // common - file system access failed
ExitCodeInsufficientOrWrongInputs = 254 // common - runtime error(insufficient or wrong input)
ExitCodeUnknownErrorPanic = 255 // common - runtime error(unknown panic)
ExitCodeSuccessful = 0
ExitCodeControlsAlarm = 1 // check - no runtime errors, 1 or more control alarms, no control errors
ExitCodeControlsError = 2 // check - no runtime errors, 1 or more control errors
ExitCodePluginLoadingError = 11 // plugin - loading error
ExitCodePluginListFailure = 12 // plugin - listing failed
ExitCodePluginNotFound = 13 // plugin - not found
ExitCodeSnapshotCreationFailed = 21 // snapshot - creation failed
ExitCodeSnapshotUploadFailed = 22 // snapshot - upload failed
ExitCodeServiceSetupFailure = 31 // service - setup failed
ExitCodeServiceStartupFailure = 32 // service - start failed
ExitCodeServiceStopFailure = 33 // service - stop failed
ExitCodeQueryExecutionFailed = 41 // query - 1 or more queries failed - change in behavior(previously the exitCode used to be the number of queries that failed)
ExitCodeLoginCloudConnectionFailed = 51 // login - connecting to cloud failed
ExitCodeInvalidExecutionEnvironment = 249 // common - when steampipe is run in an unsupported environment
ExitCodeInitializationFailed = 250 // common - initialization failed
ExitCodeBindPortUnavailable = 251 // common(service/dashboard) - port binding failed
ExitCodeNoModFile = 252 // common - no mod file
ExitCodeFileSystemAccessFailure = 253 // common - file system access failed
ExitCodeInsufficientOrWrongInputs = 254 // common - runtime error(insufficient or wrong input)
ExitCodeUnknownErrorPanic = 255 // common - runtime error(unknown panic)
)

0 comments on commit 016d373

Please sign in to comment.