Skip to content

scripts/regenerate should also update stderr.txt #2379

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

Merged
merged 1 commit into from
Jun 28, 2023
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
13 changes: 12 additions & 1 deletion scripts/regenerate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -50,12 +51,22 @@ func regenerate(dir string) error {
return nil
}

var expectFailure bool
if _, err := os.Stat(filepath.Join(cwd, "stderr.txt")); !os.IsNotExist(err) {
expectFailure = true
}

cmd := exec.Command("sqlc-dev", "generate", "--experimental")
cmd.Dir = cwd
out, failed := cmd.CombinedOutput()
if _, err := os.Stat(filepath.Join(cwd, "stderr.txt")); os.IsNotExist(err) && failed != nil {
if failed != nil && !expectFailure {
return fmt.Errorf("%s: sqlc-dev generate failed\n%s", cwd, out)
}
if expectFailure {
if err := ioutil.WriteFile(filepath.Join(cwd, "stderr.txt"), out, 0644); err != nil {
return fmt.Errorf("failed to update stderr.txt: %v", err)
}
}
}
return nil
})
Expand Down