Skip to content

internal/cmd: print correct config file on parse failure #749

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 2 commits into from
Oct 26, 2020
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
7 changes: 4 additions & 3 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ func Generate(e Env, dir string, stderr io.Writer) (map[string]string, error) {
}

if !yamlMissing && !jsonMissing {
fmt.Fprintln(stderr, "error parsing sqlc.json: both files present")
fmt.Fprintln(stderr, "error: both sqlc.json and sqlc.yaml files present")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fmt.Fprintf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't have anything interpolated... ?

The one below this one should be Fprintf, I made a mistake there, but not this one

return nil, errors.New("sqlc.json and sqlc.yaml present")
}

configPath := yamlPath
if yamlMissing {
configPath = jsonPath
}
base := filepath.Base(configPath)

blob, err := ioutil.ReadFile(configPath)
if err != nil {
fmt.Fprintln(stderr, "error parsing sqlc.json: file does not exist")
fmt.Fprintf(stderr, "error parsing %s: file does not exist\n", base)
return nil, err
}

Expand All @@ -88,7 +89,7 @@ func Generate(e Env, dir string, stderr io.Writer) (map[string]string, error) {
case config.ErrNoPackages:
fmt.Fprintf(stderr, errMessageNoPackages)
}
fmt.Fprintf(stderr, "error parsing sqlc.json: %s\n", err)
fmt.Fprintf(stderr, "error parsing %s: %s\n", base, err)
return nil, err
}

Expand Down