Skip to content

Conversation

@GeertJohan
Copy link
Member

@GeertJohan GeertJohan commented Jan 15, 2026

No description provided.

@GeertJohan GeertJohan changed the title Add --error-on-diff flag to get an exit code 2 when there were diffs … Add --error-on-diff flag to get an exit code 2 when there were diffs generated Jan 15, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new --error-on-diff flag to the generate command that allows users to receive a non-zero exit code (exit code 2) when diff statements are generated, while maintaining backward compatibility by defaulting to exit code 0 when diffs are detected.

Changes:

  • Added ErrDiffDetected error to signal when diff statements are generated
  • Implemented --error-on-diff flag in the generate command
  • Modified main.go to handle the new error and exit with code 2 when the flag is enabled

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
main.go Adds error handling logic to check for ErrDiffDetected and exit with code 2 if --error-on-diff flag is set
cmd/generate.go Defines ErrDiffDetected, adds --error-on-diff flag, and returns the error when diff statements are generated in both stdout and file modes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

cmd/generate.go:207

  • When --dev mode is combined with --error-on-diff, the continuous loop will log the error but continue running. This behavior may be confusing because the exit code 2 error is treated as a soft error in dev mode, but as a hard error otherwise. Consider documenting this behavior or adding validation to prevent using both flags together if this combination doesn't make sense for the use case.
			if dev {
				for {
					time.Sleep(time.Millisecond * 100)
					err = continuousFunc()
					if err != nil {
						log.Printf("Failed to run: %v\n", err)
					}
				}
			}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

Cool, builtin git diff --exit-code 😛

cmd/init.go Outdated
Comment on lines 166 to 167
_, err = runWithFile(
ctx, config, wd, tmpDir, migrationsDir, filepath.Join(migrationsDir, "001_init.up.sql"), 1, false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put each argument on a new line. Weird that gofmt doesn't do/enforce this already 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@GeertJohan GeertJohan force-pushed the exit-error-on-diff-statements branch from ca4b04c to a3ae571 Compare January 17, 2026 12:02
@GeertJohan GeertJohan merged commit a0b9cf1 into main Jan 17, 2026
1 check passed
@provokateurin provokateurin deleted the exit-error-on-diff-statements branch January 17, 2026 12:07
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.

2 participants