Skip to content

Commit

Permalink
check for exit code 1 with rg (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto authored Mar 15, 2022
1 parent d9e8608 commit 34c5482
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/graphql/generate_ts_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,22 @@ func getImportPathForModelFile(nodeData *schema.NodeData) string {
func searchForFiles(processor *codegen.Processor) []string {
rootPath := processor.Config.GetAbsPathToRoot()

var buf bytes.Buffer
cmd := exec.Command("rg", "-tts", "-l", strconv.Quote(strings.Join(searchFor, "|")))
// run in root dir
cmd.Dir = rootPath
cmd.Stdout = &buf
if err := cmd.Run(); err != nil {
b, err := cmd.CombinedOutput()
if err != nil {
exit, ok := err.(*exec.ExitError)
// exit code 1 is expected when there's no results. nothing to do here
if ok && exit.ExitCode() == 1 {
return nil
}
if processor.Config.DebugMode() {
fmt.Printf("error %v searching for custom files", err)
fmt.Printf("error searching for custom files: %v, output: %s\n", err, string(b))
return nil
}
return nil
}
files := strings.Split(strings.TrimSpace(buf.String()), "\n")
files := strings.Split(strings.TrimSpace(string(b)), "\n")

result := []string{}

Expand Down

0 comments on commit 34c5482

Please sign in to comment.