Skip to content

Commit

Permalink
Add ErrDuplicateMigration typed error
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius Kriukas committed Dec 12, 2019
1 parent 49ae033 commit 29df549
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion source/httpfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/golang-migrate/migrate/v4/source"
)

// ErrDuplicateMigration is an error type for reporting duplicate migration
// files.
type ErrDuplicateMigration struct {
Filename string
}

// Error implements error interface.
func (e ErrDuplicateMigration) Error() string {
return fmt.Sprintf("duplicate migration file: %s", e.Filename)
}

// Driver is a migration source driver for reading migrations from
// http.FileSystem instances. It implements source.Driver interface and can be
// used as a migration source for the main migrate library.
Expand Down Expand Up @@ -61,7 +72,9 @@ func (h *Driver) Init(fs http.FileSystem, path string) error {
}

if !ms.Append(m) {
return fmt.Errorf("duplicate migration file: %v", file.Name())
return ErrDuplicateMigration{
Filename: file.Name(),
}
}
}

Expand Down

0 comments on commit 29df549

Please sign in to comment.