Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for exit code 1 with rg #798

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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