refactor: directly return error where sufficient (#2855)

pull/2860/head^2
Clément Michaud 2022-02-09 23:07:53 +01:00 committed by GitHub
parent 8fc48476c6
commit 5d4003c291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 29 deletions

View File

@ -120,7 +120,7 @@ func doStartupChecks(config *schema.Configuration, providers *middlewares.Provid
}
}
func doStartupCheck(logger *logrus.Logger, name string, provider models.StartupCheck, disabled bool) (err error) {
func doStartupCheck(logger *logrus.Logger, name string, provider models.StartupCheck, disabled bool) error {
if disabled {
logger.Debugf("%s provider: startup check skipped as it is disabled", name)
return nil
@ -130,9 +130,5 @@ func doStartupCheck(logger *logrus.Logger, name string, provider models.StartupC
return fmt.Errorf("unrecognized provider or it is not configured properly")
}
if err = provider.StartupCheck(); err != nil {
return err
}
return nil
return provider.StartupCheck()
}

View File

@ -33,10 +33,8 @@ func storagePersistentPreRunE(cmd *cobra.Command, _ []string) (err error) {
sources = append(sources, configuration.NewYAMLFileSource(configFile))
}
} else {
if _, err := os.Stat(configs[0]); err == nil {
sources = append(sources, configuration.NewYAMLFileSource(configs[0]))
}
} else if _, err := os.Stat(configs[0]); err == nil {
sources = append(sources, configuration.NewYAMLFileSource(configs[0]))
}
mapping := map[string]string{

View File

@ -38,22 +38,12 @@ func (n *FileNotifier) StartupCheck() (err error) {
}
}
if err := os.WriteFile(n.path, []byte(""), fileNotifierMode); err != nil {
return err
}
return nil
return os.WriteFile(n.path, []byte(""), fileNotifierMode)
}
// Send send a identity verification link to a user.
func (n *FileNotifier) Send(recipient, subject, body, _ string) error {
content := fmt.Sprintf("Date: %s\nRecipient: %s\nSubject: %s\nBody: %s", time.Now(), recipient, subject, body)
err := os.WriteFile(n.path, []byte(content), fileNotifierMode)
if err != nil {
return err
}
return nil
return os.WriteFile(n.path, []byte(content), fileNotifierMode)
}

View File

@ -243,11 +243,7 @@ func (n *SMTPNotifier) StartupCheck() (err error) {
return err
}
if err := n.client.Reset(); err != nil {
return err
}
return nil
return n.client.Reset()
}
// Send is used to send an email to a recipient.

View File

@ -54,7 +54,7 @@ func (rs *RodSession) collectScreenshot(err error, page *rod.Page) {
build := os.Getenv("BUILDKITE_BUILD_NUMBER")
suite := strings.ToLower(os.Getenv("SUITE"))
job := os.Getenv("BUILDKITE_JOB_ID")
path := filepath.Join(fmt.Sprintf("%s/%s/%s/%s", base, build, suite, job)) //nolint: gocritic
path := filepath.Join(base, build, suite, job)
if err := os.MkdirAll(path, 0755); err != nil {
log.Fatal(err)

View File

@ -33,7 +33,7 @@ const (
const (
// Hour is an int based representation of the time unit.
Hour = time.Minute * 60 //nolint: revive
Hour = time.Minute * 60 //nolint:revive
// Day is an int based representation of the time unit.
Day = Hour * 24