Skip to content

Commit

Permalink
fix: show execution error
Browse files Browse the repository at this point in the history
  • Loading branch information
becojo committed Nov 19, 2024
1 parent 157117a commit 36324ae
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/semsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,10 @@ func (s *State) Prepare() {
}
}

func (s *State) Exec() {
func (s *State) Exec() error {
rulefile, err := s.Tempfile("semsearch-rule-")
if err != nil {
fmt.Fprintln(os.Stderr, "Error: failed to create temporary rule file")
return
return err
}

s.Configs = append(s.Configs, rulefile.Name())
Expand All @@ -329,13 +328,13 @@ func (s *State) Exec() {

if s.Export {
yaml.NewEncoder(os.Stdout).Encode(rules)
return
return nil
}

cmd := exec.Command("semgrep", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
return cmd.Run()
}

func main() {
Expand All @@ -349,5 +348,9 @@ func main() {

state.Build(os.Args[1:])
state.Prepare()
state.Exec()
err := state.Exec()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

0 comments on commit 36324ae

Please sign in to comment.