Add validation for config file extensions with clear error messages#691
Open
Add validation for config file extensions with clear error messages#691
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>
Copilot
AI
changed the title
[WIP] Add validation for unsupported config file extensions
Add validation for config file extensions with clear error messages
Feb 2, 2026
There was a problem hiding this comment.
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 |
Contributor
|
@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>
Contributor
|
@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>
Contributor
|
@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>
dlevy-msft-sql
approved these changes
Feb 2, 2026
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.
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.