Skip to content

Commit

Permalink
printing wrong error, removed empty else
Browse files Browse the repository at this point in the history
  • Loading branch information
abs3ntdev committed Mar 9, 2023
1 parent 11a6f50 commit aa16295
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ func InstallCode(cmd *cobra.Command, args []string) {

err = migrate.LockExecTx(ctx, conn, sql)
if err != nil {
if err, ok := err.(migrate.MigrationPgError); ok {
fmt.Fprintln(os.Stderr, err)
if err.Detail != "" {
fmt.Fprintln(os.Stderr, "DETAIL:", err.Detail)
if migrationpgError, ok := err.(migrate.MigrationPgError); ok {
fmt.Fprintln(os.Stderr, migrationpgError)
if migrationpgError.Detail != "" {
fmt.Fprintln(os.Stderr, "DETAIL:", migrationpgError.Detail)
}

if err.Position != 0 {
ele, err := migrate.ExtractErrorLine(err.Sql, int(err.Position))
if migrationpgError.Position != 0 {
ele, err := migrate.ExtractErrorLine(migrationpgError.Sql, int(migrationpgError.Position))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
10 changes: 5 additions & 5 deletions migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"github.com/jackc/tern/v2/migrate/internal/sqlsplit"
)

var migrationPattern = regexp.MustCompile(`\A(\d+)_.+\.sql\z`)
var disableTxPattern = regexp.MustCompile(`(?m)^---- tern: disable-tx ----$`)
var (
migrationPattern = regexp.MustCompile(`\A(\d+)_.+\.sql\z`)
disableTxPattern = regexp.MustCompile(`(?m)^---- tern: disable-tx ----$`)
)

var ErrNoFwMigration = errors.New("no sql in forward migration step")

Expand All @@ -37,8 +39,7 @@ func (e IrreversibleMigrationError) Error() string {
return fmt.Sprintf("Irreversible migration: %d - %s", e.m.Sequence, e.m.Name)
}

type NoMigrationsFoundError struct {
}
type NoMigrationsFoundError struct{}

func (e NoMigrationsFoundError) Error() string {
return "migrations not found"
Expand Down Expand Up @@ -331,7 +332,6 @@ func (m *Migrator) MigrateTo(ctx context.Context, targetVersion int32) (err erro
if disableTxPattern.MatchString(sql) {
useTx = false
sql = disableTxPattern.ReplaceAllLiteralString(sql, "")
} else {
}

if useTx {
Expand Down

0 comments on commit aa16295

Please sign in to comment.