Skip to content

Commit 2fdda08

Browse files
committed
Handle error out of prompt
1 parent 6149b55 commit 2fdda08

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

internal/dependencymanager/dependencyinstaller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,11 @@ func (di *DependencyInstaller) handleFoundContract(networkName, contractAddr, co
492492
// If no hash, ignore
493493
if dependency != nil && dependency.Hash != "" && dependency.Hash != originalContractDataHash {
494494
msg := fmt.Sprintf("The latest version of %s is different from the one you have locally. Do you want to update it?", contractName)
495-
if !prompt.GenericBoolPrompt(msg) {
495+
shouldUpdate, err := prompt.GenericBoolPrompt(msg)
496+
if err != nil {
497+
return err
498+
}
499+
if !shouldUpdate {
496500
return nil
497501
}
498502
}

internal/prompt/prompt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,13 @@ func InstallPathPrompt(defaultPath string) string {
674674
return filepath.Clean(install)
675675
}
676676

677-
func GenericBoolPrompt(msg string) bool {
677+
func GenericBoolPrompt(msg string) (bool, error) {
678678
result, err := RunSingleSelect([]string{"Yes", "No"}, msg)
679679
if err != nil {
680-
os.Exit(-1)
680+
return false, err
681681
}
682682

683-
return result == "Yes"
683+
return result == "Yes", nil
684684
}
685685

686686
func GenericSelect(items []string, message string) string {

internal/super/init.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ func startInteractiveInit(
258258
}
259259

260260
msg := "Would you like to install any standard Flow contracts and their dependencies?"
261-
if prompt.GenericBoolPrompt(msg) {
261+
installContracts, err := prompt.GenericBoolPrompt(msg)
262+
if err != nil {
263+
return "", err
264+
}
265+
if installContracts {
262266
err := dependencymanager.PromptInstallCoreContracts(logger, state, tempDir, nil)
263267
if err != nil {
264268
return "", err

0 commit comments

Comments
 (0)