mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 13:34:23 +01:00
Return non-0 exit code from DetectGit (#1461)
* fix(detect): exit code for git errors * chore(detect): add consistent error msgs
This commit is contained in:
1 parent
0334ec1076
commit
80bd1779e3
1 file changed
+15
-10
+15
-10
@@ -39,7 +39,7 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
// grab source
|
// grab source
|
||||||
source, err := cmd.Flags().GetString("source")
|
source, err := cmd.Flags().GetString("source")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("could not get source")
|
||||||
}
|
}
|
||||||
detector := Detector(cmd, cfg, source)
|
detector := Detector(cmd, cfg, source)
|
||||||
|
|
||||||
@@ -58,41 +58,46 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
fromPipe, err := cmd.Flags().GetBool("pipe")
|
fromPipe, err := cmd.Flags().GetBool("pipe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err)
|
log.Fatal().Err(err).Msg("could not call GetBool() for pipe")
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the detector scan
|
// start the detector scan
|
||||||
if noGit {
|
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 {
|
if err != nil {
|
||||||
log.Fatal().Err(err)
|
log.Fatal().Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
findings, err = detector.DetectFiles(paths)
|
findings, err = detector.DetectFiles(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// don't exit on error, just log it
|
// don't exit on error, just log it
|
||||||
log.Error().Err(err).Msg("")
|
log.Error().Err(err).Msg("failed scan directory")
|
||||||
}
|
}
|
||||||
} else if fromPipe {
|
} else if fromPipe {
|
||||||
findings, err = detector.DetectReader(os.Stdin, 10)
|
findings, err = detector.DetectReader(os.Stdin, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log fatal to exit, no need to continue since a report
|
// log fatal to exit, no need to continue since a report
|
||||||
// will not be generated when scanning from a pipe...for now
|
// 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 {
|
} else {
|
||||||
var logOpts string
|
var (
|
||||||
|
gitCmd *sources.GitCmd
|
||||||
|
logOpts string
|
||||||
|
)
|
||||||
logOpts, err = cmd.Flags().GetString("log-opts")
|
logOpts, err = cmd.Flags().GetString("log-opts")
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("")
|
log.Fatal().Err(err).Msg("could not create Git cmd")
|
||||||
}
|
}
|
||||||
findings, err = detector.DetectGit(gitCmd)
|
findings, err = detector.DetectGit(gitCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// don't exit on error, just log it
|
// don't exit on error, just log it
|
||||||
log.Error().Err(err).Msg("")
|
log.Error().Err(err).Msg("failed to scan Git repository")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user