Skip to content

fix(verify): Return an error on failures #3427

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 6, 2024
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
11 changes: 7 additions & 4 deletions internal/cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"database/sql"
"errors"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -75,6 +76,7 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
existing[qs.Name] = qs
}

var verr error
for _, qs := range previous.QuerySets {
// TODO: Create a function for this so that we can return early on errors

Expand Down Expand Up @@ -121,30 +123,31 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
}
defer db.Close()

var qerr error
for _, query := range codegen.Queries {
stmt, err := db.PrepareContext(ctx, query.Text)
if err != nil {
fmt.Fprintf(stderr, "Failed to prepare the following query:\n")
fmt.Fprintf(stderr, "%s\n", query.Text)
fmt.Fprintf(stderr, "Error was: %s\n", err)
qerr = err
continue
}
if err := stmt.Close(); err != nil {
slog.Error("stmt.Close failed", "err", err)
}
}

return nil
return qerr
}

if err := check(); err != nil {
verr = errors.New("errored")
fmt.Fprintf(stderr, "FAIL\t%s\n", qs.Name)
} else {
fmt.Fprintf(stderr, "ok\t%s\n", qs.Name)
}
}

// return fmt.Errorf("BREAKING CHANGES DETECTED")

return nil
return verr
}
Loading