Skip to content

Commit

Permalink
Merge pull request #162 from sol-eng/add-steps-to-error-messages
Browse files Browse the repository at this point in the history
Wrap all error messages with a helpful message on the return step to use
  • Loading branch information
samcofer authored May 12, 2023
2 parents 427d3e4 + 2a10e7f commit 0113383
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ func newSetup(setupOpts setupOpts) error {
// Check if running as root
err := operatingsystem.CheckIfRunningAsRoot()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step start\"", err)
}

// Determine OS and install pre-requisites
osType, err := operatingsystem.DetectOS()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step start\"", err)
}

if step == "prereqs" {
ConfirmInstall, err := operatingsystem.PromptInstallPrereqs()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step prereqs\"", err)
}

if ConfirmInstall {
Expand All @@ -68,7 +68,7 @@ func newSetup(setupOpts setupOpts) error {
log.Fatal("Exited Workbench Installer")
}
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step prereqs\"", err)
}
step = "firewall"
}
Expand All @@ -78,19 +78,19 @@ func newSetup(setupOpts setupOpts) error {
// TODO: Add support for Ubuntu ufw
firewalldEnabled, err := operatingsystem.CheckFirewallStatus(osType)
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step firewall\"", err)
}

if firewalldEnabled {
disableFirewall, err := operatingsystem.FirewallPrompt()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step firewall\"", err)
}

if disableFirewall {
err = operatingsystem.DisableFirewall(osType)
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step firewall\"", err)
}
}
}
Expand All @@ -102,19 +102,19 @@ func newSetup(setupOpts setupOpts) error {
// TODO: Add support for Ubuntu AppArmor
selinuxEnabled, err := operatingsystem.CheckLinuxSecurityStatus(osType)
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step security\"", err)
}

if selinuxEnabled {
disableSELinux, err := operatingsystem.LinuxSecurityPrompt(osType)
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step security\"", err)
}

if disableSELinux {
err = operatingsystem.DisableLinuxSecurity()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step security\"", err)
}
}
}
Expand All @@ -126,7 +126,7 @@ func newSetup(setupOpts setupOpts) error {
// Languages
selectedLanguages, err = languages.PromptAndRespond()
if err != nil {
return fmt.Errorf("issue selecting languages: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step languages\"", err)
}
step = "r"
}
Expand All @@ -135,7 +135,7 @@ func newSetup(setupOpts setupOpts) error {
// R
err = languages.ScanAndHandleRVersions(osType)
if err != nil {
return fmt.Errorf("issue scanning, prompting or installing R: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step r\"", err)
}
step = "python"
}
Expand All @@ -145,7 +145,7 @@ func newSetup(setupOpts setupOpts) error {
if lo.Contains(selectedLanguages, "python") {
err := languages.ScanAndHandlePythonVersions(osType)
if err != nil {
return fmt.Errorf("issue scanning, prompting or installing Python: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step python\"", err)
}
}
step = "workbench"
Expand All @@ -155,7 +155,7 @@ func newSetup(setupOpts setupOpts) error {
// Workbench
err = workbench.CheckPromptDownloadAndInstallWorkbench(osType)
if err != nil {
return fmt.Errorf("issue checking, prompting, downloading or installing Workbench: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step workbench\"", err)
}
step = "license"
}
Expand All @@ -164,7 +164,7 @@ func newSetup(setupOpts setupOpts) error {
// Licensing
err = license.CheckPromptAndActivateLicense()
if err != nil {
return fmt.Errorf("issue checking, prompting or activating license: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step license\"", err)
}
step = "jupyter"
}
Expand All @@ -173,7 +173,7 @@ func newSetup(setupOpts setupOpts) error {
// Jupyter
err = jupyter.ScanPromptInstallAndConfigJupyter()
if err != nil {
return fmt.Errorf("issue scanning, prompting, installing or configuring Jupyter: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step jupyter\"", err)
}
step = "prodrivers"
}
Expand All @@ -182,7 +182,7 @@ func newSetup(setupOpts setupOpts) error {
// Pro Drivers
err = prodrivers.CheckPromptDownloadAndInstallProDrivers(osType)
if err != nil {
return fmt.Errorf("issue checking, prompting, downloading or installing Pro Drivers: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step prodrivers\"", err)
}
step = "ssl"
}
Expand All @@ -191,20 +191,20 @@ func newSetup(setupOpts setupOpts) error {
// SSL
sslChoice, err := ssl.PromptSSL()
if err != nil {
return fmt.Errorf("issue selecting if SSL is to be used: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step ssl\"", err)
}
if sslChoice {
serverURL, err := ssl.PromptServerURL()
if err != nil {
return fmt.Errorf("issue prompting for server URL: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step ssl\"", err)
}
certPath, keyPath, err := ssl.PromptAndVerifySSL(osType)
if err != nil {
return fmt.Errorf("issue verifying and configuring SSL: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step ssl\"", err)
}
workbench.WriteSSLConfig(certPath, keyPath, serverURL)
if err != nil {
return fmt.Errorf("error writing ssl configuration to file rserver.conf: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step ssl\"", err)
}
}
step = "packagemanager"
Expand All @@ -214,22 +214,22 @@ func newSetup(setupOpts setupOpts) error {
// Package Manager URL
packageManagerChoice, err := packagemanager.PromptPackageManagerChoice()
if err != nil {
return fmt.Errorf("issue in prompt for Posit Package Manager choice: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step packagemanager\"", err)
}
if packageManagerChoice {
err = packagemanager.InteractivePackageManagerPrompts(osType)
if err != nil {
return fmt.Errorf("issue in interactive Posit Package Manager repo verification steps: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step packagemanager\"", err)
}
} else {
publicPackageManagerChoice, err := packagemanager.PromptPublicPackageManagerChoice()
if err != nil {
return fmt.Errorf("issue in prompt for Posit Public Package Manager choice: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step packagemanager\"", err)
}
if publicPackageManagerChoice {
err = packagemanager.VerifyAndBuildPublicPackageManager(osType)
if err != nil {
return fmt.Errorf("issue in verifying and building Public Posit Package Manager URL and repo: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step packagemanager\"", err)
}
}
}
Expand All @@ -240,12 +240,12 @@ func newSetup(setupOpts setupOpts) error {
// Connect URL
connectChoice, err := connect.PromptConnectChoice()
if err != nil {
return fmt.Errorf("issue in prompt for Connect URL choice: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step connect\"", err)
}
if connectChoice {
err = connect.PromptVerifyAndConfigConnect()
if err != nil {
return fmt.Errorf("issue in prompting, verifying and saving Connect URL: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step connect\"", err)
}
}
step = "restart"
Expand All @@ -256,7 +256,7 @@ func newSetup(setupOpts setupOpts) error {

err = workbench.RestartRStudioServerAndLauncher()
if err != nil {
return fmt.Errorf("issue restarting RStudio Server and Launcher: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step restart\"", err)
}
step = "status"
}
Expand All @@ -266,25 +266,25 @@ func newSetup(setupOpts setupOpts) error {

err = workbench.StatusRStudioServerAndLauncher()
if err != nil {
return fmt.Errorf("issue running status for RStudio Server and Launcher: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step status\"", err)
}
step = "verify"
}

if step == "verify" {
verifyChoice, err := workbench.PromptInstallVerify()
if err != nil {
return fmt.Errorf("issue selecting if verification is to be run: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step verify\"", err)
}
if verifyChoice {
username, skip, err := operatingsystem.PromptAndVerifyUser()
if err != nil {
return err
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step verify\"", err)
}
if !skip {
err = workbench.VerifyInstallation(username)
if err != nil {
return fmt.Errorf("issue running verification: %w", err)
return fmt.Errorf("%w.\nTo return to this step in the setup process use \"wbi setup --step verify\"", err)
}
}
}
Expand Down

0 comments on commit 0113383

Please sign in to comment.