func ignoreErrors(errors []error, e *parsecli.Env) string { l := len(errors) var b bytes.Buffer for n, err := range errors { b.WriteString(parsecli.ErrorString(e, err)) if n != l-1 { b.WriteString("\n") } } return b.String() }
func (d *deployCmd) handleError( n int, err, prevErr error, e *parsecli.Env, ) error { if err == nil { return nil } if n == d.Retries-1 { return err } var waitTime time.Duration if d.wait != nil { waitTime = d.wait(n) } errStr := parsecli.ErrorString(e, err) if prevErr != nil { prevErrStr := parsecli.ErrorString(e, prevErr) if prevErrStr == errStr { fmt.Fprintf( e.Err, "Sorry, deploy failed again with same error.\nWill retry in %d seconds.\n\n", waitTime/time.Second, ) time.Sleep(waitTime) return nil } } fmt.Fprintf( e.Err, "Deploy failed with error:\n%s\nWill retry in %d seconds.\n\n", errStr, waitTime/time.Second, ) time.Sleep(waitTime) return nil }
func GetLinkedHerokuAppConfig(app *parsecli.App, e *parsecli.Env) (bool, *parsecli.HerokuAppConfig, error) { h := &herokuLink{parseAppID: app.ApplicationID} apps, err := h.getAppLinks(e) if err != nil { return false, nil, err } if len(apps) == 0 { randomName := getRandomAppName(app) appName := randomName for i := 0; i < 3; i++ { if appName == randomName { fmt.Fprintf(e.Out, `Let's create a new Heroku app in which server code will be run. The Heroku app will be named: %q Note that this can be changed later using Heroku API or Dashboard. `, randomName, ) } else { appName = h.getHerokuAppName(e) } id, err := h.createNewLink(e, appName) if err == nil { return true, &parsecli.HerokuAppConfig{ ParseAppID: app.ApplicationID, HerokuAppID: id, }, nil } if i == 2 { return false, nil, err } switch { case stackerr.HasUnderlying(err, stackerr.MatcherFunc(herokuAppNameTaken)): fmt.Fprintf(e.Err, "App name %s already taken.\nPlease try again...\n\n", appName) appName = "" case stackerr.HasUnderlying(err, stackerr.MatcherFunc(herokuAccountNotLinked)): fmt.Fprintf(e.Err, `Looks like you have not yet linked your Heroku Account to your Parse account. Trying to open %q in the browser. Please click "Link Heroku" button at the bottom. `, linkHerokuURL, ) appName = randomName err := open.Run(linkHerokuURL) if err != nil { fmt.Fprintf(e.Err, `Sorry, we couldn’t open the browser for you. Go to %q and click the "Link Heroku" button to link your Heroku account to Parse. `, linkHerokuURL, ) } fmt.Fprintf(e.Out, "Press ENTER when you are done linking your Heroku account to Parse: ") var discard string fmt.Fscanf(e.In, "%s\n", &discard) default: return false, nil, err } } } if len(apps) == 1 { return false, &parsecli.HerokuAppConfig{ ParseAppID: app.ApplicationID, HerokuAppID: apps[0].id, }, nil } // NOTE: this part of code will not be used for now for r := 0; r < 3; r++ { selected, err := selectHerokuApp(apps, e) if err != nil { fmt.Fprintf(e.Err, "error: %s.\nPlease try again...\n", parsecli.ErrorString(e, err)) continue } if selected.id != "" { return false, &parsecli.HerokuAppConfig{ ParseAppID: app.ApplicationID, HerokuAppID: selected.id, }, nil } id, err := h.createNewLink(e, selected.name) if err != nil { return false, nil, err } return false, &parsecli.HerokuAppConfig{ ParseAppID: app.ApplicationID, HerokuAppID: id, }, nil } return false, nil, stackerr.New("failed to selected an heroku app in 3 attempts") }