Fixed error handling
Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
parent
dc586b2495
commit
34e1b47968
|
@ -911,20 +911,17 @@ func importRules(url *url.URL, start, end, outputDir string, evalInterval time.D
|
||||||
} else {
|
} else {
|
||||||
etime, err = parseTime(end)
|
etime, err = parseTime(end)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "error parsing end time:", err)
|
return fmt.Errorf("error parsing end time: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stime, err = parseTime(start)
|
stime, err = parseTime(start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "error parsing start time:", err)
|
return fmt.Errorf("error parsing start time: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !stime.Before(etime) {
|
if !stime.Before(etime) {
|
||||||
fmt.Fprintln(os.Stderr, "start time is not before end time")
|
return errors.New("start time is not before end time")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := ruleImporterConfig{
|
cfg := ruleImporterConfig{
|
||||||
|
@ -937,25 +934,24 @@ func importRules(url *url.URL, start, end, outputDir string, evalInterval time.D
|
||||||
Address: url.String(),
|
Address: url.String(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "new api client error", err)
|
return fmt.Errorf("new api client error: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleImporter := newRuleImporter(log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)), cfg, v1.NewAPI(client))
|
ruleImporter := newRuleImporter(log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)), cfg, v1.NewAPI(client))
|
||||||
errs := ruleImporter.loadGroups(ctx, files)
|
errs := ruleImporter.loadGroups(ctx, files)
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "rule importer parse error", err)
|
return fmt.Errorf("rule importer parse error: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errs = ruleImporter.importAll(ctx)
|
errs = ruleImporter.importAll(ctx)
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
if err != nil {
|
fmt.Fprintln(os.Stderr, "rule importer error:", err)
|
||||||
fmt.Fprintln(os.Stderr, "rule importer error", err)
|
}
|
||||||
}
|
if len(errs) > 0 {
|
||||||
|
return errors.New("error importing rules")
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue