Skip to content

fix: validate config file extension before use#705

Open
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:fix-config-extension-validation
Open

fix: validate config file extension before use#705
dlevy-msft-sql wants to merge 2 commits intomicrosoft:mainfrom
dlevy-msft-sql:fix-config-extension-validation

Conversation

@dlevy-msft-sql
Copy link
Contributor

Problem

When users specify a config file with an unsupported extension (e.g., --sqlconfig myfile.txt), they receive a confusing Viper error: Unsupported Config Type 'txt'.

Root Cause

No validation of the file extension before passing to Viper.

Code Change

Added validateConfigFileExtension() that provides a clear error message:

Configuration files must use YAML format (.yaml or .yml extension).
File 'myfile.txt' has unsupported extension '.txt'.

Allowed extensions:

  • .yaml / .yml (case-insensitive)
  • No extension (for default ~/.sqlcmd/sqlconfig)

The validation runs before creating the file, preventing creation of unusable config files.

Testing

  • Build passes: go build ./...
  • All internal/config tests pass including new tests:
    • Test_configureViperValidExtensions
    • Test_configureViperInvalidExtension
    • Test_validateConfigFileExtension

Fixes #690

Provide clear error message when user specifies a config file
with unsupported extension (e.g., .txt, .json). Only .yaml,
.yml, and no extension are allowed.
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.

Add validation/warning for unsupported config file extensions

1 participant