Skip to content

Commit

Permalink
Return non-0 exit code from DetectGit (#1461)
Browse files Browse the repository at this point in the history
* fix(detect): exit code for git errors

* chore(detect): add consistent error msgs
  • Loading branch information
rgmz authored Aug 7, 2024
1 parent 0334ec1 commit 80bd177
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions cmd/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func runDetect(cmd *cobra.Command, args []string) {
// grab source
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("could not get source")
}
detector := Detector(cmd, cfg, source)

Expand All @@ -58,41 +58,46 @@ func runDetect(cmd *cobra.Command, args []string) {
}
fromPipe, err := cmd.Flags().GetBool("pipe")
if err != nil {
log.Fatal().Err(err)
log.Fatal().Err(err).Msg("could not call GetBool() for pipe")
}

// start the detector scan
if noGit {
paths, err := sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks)
var paths <-chan sources.ScanTarget
paths, err = sources.DirectoryTargets(source, detector.Sema, detector.FollowSymlinks)
if err != nil {
log.Fatal().Err(err)
}

findings, err = detector.DetectFiles(paths)
if err != nil {
// don't exit on error, just log it
log.Error().Err(err).Msg("")
log.Error().Err(err).Msg("failed scan directory")
}
} else if fromPipe {
findings, err = detector.DetectReader(os.Stdin, 10)
if err != nil {
// log fatal to exit, no need to continue since a report
// will not be generated when scanning from a pipe...for now
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("failed scan input from stdin")
}
} else {
var logOpts string
var (
gitCmd *sources.GitCmd
logOpts string
)
logOpts, err = cmd.Flags().GetString("log-opts")
if err != nil {
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("could not call GetString() for log-opts")
}
gitCmd, err := sources.NewGitLogCmd(source, logOpts)
gitCmd, err = sources.NewGitLogCmd(source, logOpts)
if err != nil {
log.Fatal().Err(err).Msg("")
log.Fatal().Err(err).Msg("could not create Git cmd")
}
findings, err = detector.DetectGit(gitCmd)
if err != nil {
// don't exit on error, just log it
log.Error().Err(err).Msg("")
log.Error().Err(err).Msg("failed to scan Git repository")
}
}

Expand Down

0 comments on commit 80bd177

Please sign in to comment.