-
Notifications
You must be signed in to change notification settings - Fork 82
Add validation for config file extensions with clear error messages #691
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
There was a problem hiding this 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 validation for configuration file extensions to provide clear, user-friendly error messages when users specify unsupported file extensions for the --sqlconfig flag. Previously, users would receive Viper's cryptic "Unsupported Config Type" error.
Changes:
- Added
validateConfigFileExtension()function to check file extensions (.yaml, .yml, or no extension) in a case-insensitive manner - Modified
configureViper()to return an error instead of void, enabling proper error propagation - Added comprehensive test coverage with 10 test cases covering valid extensions, invalid extensions, and edge cases
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/config/viper.go | Implements validation logic for config file extensions and updates configureViper to return errors |
| internal/config/config.go | Updates SetFileName to handle errors from configureViper using checkErr |
| internal/config/viper_test.go | Adds comprehensive test coverage for extension validation including valid, invalid, and edge cases |
|
@copilot you've got review comments to fix |
Move validateConfigFileExtension call before file.CreateEmptyIfNotExists to avoid creating unnecessary files with invalid extensions on the filesystem. This addresses the review comment by ensuring validation happens first. Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
There was a problem hiding this 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 1 comment.
|
@copilot fix the review comment |
Changed multi-line error message to single-line format to maintain consistency with error message patterns throughout the codebase. Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
There was a problem hiding this 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 1 comment.
|
@copilot fix the review issues |
Added test cases for edge scenarios: - Files with multiple dots (my.config.yaml, config.backup.txt) - Hidden files with extensions (.config.yaml, .config.txt) - Files with only dot and extension (.yaml, .yml) Total test cases increased from 10 to 19, improving coverage for various filename patterns that users might encounter. Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
There was a problem hiding this 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 no new comments.
Plan: Add validation/warning for unsupported config file extensions
internal/config/viper.goSetFileName()ininternal/config/config.goto validate extension before callingconfigureViper()localizer.Errorf()internal/config/viper_test.gofor:Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.