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

Do not return an error when no change. Communicate error conditions using errors. #1063

Open
atljoseph opened this issue Mar 23, 2024 · 0 comments

Comments

@atljoseph
Copy link

It is good to know when a migration is not needed, but that is a valid state in a system.
So, why is there an error when all migrations already been ran?
Why are you communicating informational conditions using errors?
Errors should be reserved for errors.
Please return a struct from Up and Down which lists information conditions (stats, if you will).
Please remove the return of error when all migrations have been performed, and no changes would result.
Can't imagine when that would ever be a valid condition for an error.
No changes? Great! Sail the seas of cheese!

if migrateErr := m.Up(); migrateErr != nil {
        // No change is not an error condition. It is the DESIRED condition.. .To be up to date.
	if !errors.Is(migrateErr, migrate.ErrNoChange) {
		return fmt.Errorf("cannot perform database migration: %w", migrateErr)
	}
}
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

No branches or pull requests

1 participant