Exit with non-zero code when database is not accessible#326
Open
OdenTakashi wants to merge 1 commit intomainfrom
Open
Exit with non-zero code when database is not accessible#326OdenTakashi wants to merge 1 commit intomainfrom
OdenTakashi wants to merge 1 commit intomainfrom
Conversation
## Problem AnnotationDecider#annotate? has a catch-all `rescue => e` that returns false for any StandardError, including database connection errors. While error messages are printed to stderr, the command still exits with code 0 because the errors are treated as "skip this file" rather than a fatal condition. This is problematic for CI workflows using `--frozen`, where a non-zero exit code is expected on failure. ## Solution Add a specific rescue for ActiveRecord::ConnectionNotEstablished and ActiveRecord::NoDatabaseError before the catch-all handler. These errors now abort with a clear message and exit code 1, instead of being swallowed by the catch-all and treated as a skippable file-level issue. Other errors (e.g. model syntax errors, LoadError) continue to be rescued and skipped as before. refs: #240
a3d0f38 to
3c4058b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AnnotationDecider#annotate? has a catch-all
rescue => ethat returns false for any StandardError, including database connection errors. While error messages are printed to stderr, the command still exits with code 0 because the errors are treated as "skip this file" rather than a fatal condition. This is problematic for CI workflows using--frozen, where a non-zero exit code is expected on failure.Solution
Add a specific rescue for ActiveRecord::ConnectionNotEstablished and ActiveRecord::NoDatabaseError before the catch-all handler. These errors now abort with a clear message and exit code 1, instead of being swallowed by the catch-all and treated as a skippable file-level issue. Other errors (e.g. model syntax errors, LoadError) continue to be rescued and skipped as before.
Follow-up
exe/annotaterb already has a # TODO: Return exit status comment, and Runner#run does not currently return a meaningful exit status.
As a follow-up, it may make sense to centralize error handling at the Runner or exe/annotaterb level. For example, the entire execution could be wrapped in a single top-level rescue that catches errors, prints a user-friendly message, and exits with a non-zero status. This would allow error handling to be managed in one place, rather than requiring specific exceptions to be handled in lower-level code such as AnnotationDecider.
ridgepole takes this approach.
However, that would move this change closer to the broader error-handling design, so it has been kept out of scope for this PR.
refs: #240