Skip to content
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

Improve error message in case no migration is found #158

Merged
merged 5 commits into from
Aug 30, 2019

Conversation

dotchev
Copy link
Contributor

@dotchev dotchev commented Jan 23, 2019

In case no migration is found for the current version, we got this error

file does not exist

Now we get an error like this

no migration found for version 6

Fixes #79

@coveralls
Copy link

Pull Request Test Coverage Report for Build 287

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 59.188%

Totals Coverage Status
Change from base Build 285: 0.0%
Covered Lines: 773
Relevant Lines: 1306

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jan 23, 2019

Pull Request Test Coverage Report for Build 532

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 51.459%

Totals Coverage Status
Change from base Build 530: 0.05%
Covered Lines: 2346
Relevant Lines: 4559

💛 - Coveralls

@@ -753,7 +753,7 @@ func (m *Migrate) versionExists(version uint) error {
return err
}

return os.ErrNotExist
Copy link
Member

Choose a reason for hiding this comment

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

I love the idea of showing which migration failed but this is a backwards incompatible change. e.g. there could be a bunch of code that relies on it as shown by all of your test changes below

A cleaner solution may be to add a logging statement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, now it returns a similar error so the tests do not change

Copy link
Member

Choose a reason for hiding this comment

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

Using os.PathError is a much better approach!

However, this is still not a backwards compatible change since existing checks against os.ErrNotExist will fail in this case. e.g. existing checks will need to use os.IsNotExists() instead. The unit tests happen to already be using os.IsNotExists().

Do you have a test case or scenario (not in the unittests where the sources are stubbed) in which a os.PathError will be returned?

migrate.go Outdated
@@ -753,6 +753,7 @@ func (m *Migrate) versionExists(version uint) error {
return err
}

m.logPrintf("ERROR: No migration found for version %d", version)
Copy link
Member

Choose a reason for hiding this comment

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

The convention in this code base is to use error: instead of ERROR:

@freeyoung
Copy link

+1 for logging a proper message here, as file does not exist is indeed confusing.
Is there any chance to push this PR forward?

@dhui
Copy link
Member

dhui commented May 16, 2019

@freeyoung Feel free to open a new PR that supersedes this one.
e.g. use m.logErr()

@dhui dhui merged commit 3dc8182 into golang-migrate:master Aug 30, 2019
gopherbot pushed a commit to golang/pkgsite that referenced this pull request Jun 15, 2020
github.com/golang-migrate/migrate is upgraded from v4.3.1 to v4.6.2, which
provides the following features that are useful:

* Running `migrate down` now prompts a confirmation, so that you
can't accidentally drop the whole database. `migrate down -all` is
available to replicate the old behavior
* Improved error messages (golang-migrate/migrate#158)

Details are at https://github.com/golang-migrate/migrate/releases.


Change-Id: I9e942f0c164a0fd62ed2e74c949da0c10d1b8d97
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/549075
Reviewed-by: Robert Findley <rfindley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting "error: file does not exist"
4 participants