Skip to content

Commit

Permalink
return non 0 errcode if ingestion has errors (guacsec#237)
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Lum <[email protected]>

Signed-off-by: Brandon Lum <[email protected]>
  • Loading branch information
lumjjb authored Nov 17, 2022
1 parent e6319db commit 65e0470
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/guacone/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,27 @@ var exampleCmd = &cobra.Command{
}

totalNum := 0
gotErr := false
// Set emit function to go through the entire pipeline
emit := func(d *processor.Document) error {
totalNum += 1
start := time.Now()

docTree, err := processorFunc(d)
if err != nil {
gotErr = true
return fmt.Errorf("unable to process doc: %v, fomat: %v, document: %v", err, d.Format, d.Type)
}

graphs, err := ingestorFunc(docTree)
if err != nil {
gotErr = true
return fmt.Errorf("unable to ingest doc tree: %v", err)
}

err = assemblerFunc(graphs)
if err != nil {
gotErr = true
return fmt.Errorf("unable to assemble graphs: %v", err)
}
t := time.Now()
Expand All @@ -132,7 +136,12 @@ var exampleCmd = &cobra.Command{
if err := collector.Collect(ctx, emit, errHandler); err != nil {
logger.Fatal(err)
}
logger.Infof("completed ingesting %v documents", totalNum)

if gotErr {
logger.Fatalf("completed ingestion with errors")
} else {
logger.Infof("completed ingesting %v documents", totalNum)
}
},
}

Expand Down

0 comments on commit 65e0470

Please sign in to comment.