Add --error-on-diff flag to get an exit code 2 when there were diffs generated#47
Conversation
There was a problem hiding this comment.
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
ErrDiffDetectederror to signal when diff statements are generated - Implemented
--error-on-diffflag 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.
a306240 to
b1d43f6
Compare
There was a problem hiding this comment.
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.
b1d43f6 to
ca4b04c
Compare
There was a problem hiding this comment.
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
--devmode 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.
provokateurin
left a comment
There was a problem hiding this comment.
Cool, builtin git diff --exit-code 😛
cmd/init.go
Outdated
| _, err = runWithFile( | ||
| ctx, config, wd, tmpDir, migrationsDir, filepath.Join(migrationsDir, "001_init.up.sql"), 1, false) |
There was a problem hiding this comment.
Put each argument on a new line. Weird that gofmt doesn't do/enforce this already 🤔
ca4b04c to
a3ae571
Compare
No description provided.