Skip to content

fix: reject non-YAML extensions for --sqlconfig flag#684

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/add-documentation-for-config-types
Closed

fix: reject non-YAML extensions for --sqlconfig flag#684
Copilot wants to merge 5 commits intomainfrom
copilot/add-documentation-for-config-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Problem

--sqlconfig only supports YAML (viper.SetConfigType("yaml") is hardcoded, Save() uses yaml.Marshal), but passing a file with a non-YAML extension (e.g. foo.json) silently parses it as YAML, producing garbage or a cryptic error. No validation, no documentation.

Root Cause

SetFileName accepted any path without checking the extension. No docs mentioned the YAML-only constraint.

Solution

  1. Validate the file extension in config.SetFileName: if an extension is present, it must be .yaml or .yml. Extensionless files (like the default ~/.sqlcmd/sqlconfig) are allowed.
  2. Document the YAML requirement in the README and --sqlconfig help text.
  3. Regenerate catalog.go and locale files via go generate.

Changes

File Change
internal/config/config.go Add extension validation in SetFileName
internal/config/config_test.go Add TestNegConfig_SetFileNameBadExtension covering .json, .toml, .yaml, .yml
README.md Add Custom Configuration Files section documenting YAML format and extension requirements
cmd/modern/root.go Update --sqlconfig help text to YAML configuration file (.yaml or .yml extension)
internal/translations/catalog.go Regenerated via go generate
internal/translations/locales/*/out.gotext.json Regenerated locale entries for new help string

Testing

  • go build ./cmd/modern passes
  • go vet ./... passes
  • go test ./internal/config/ passes (including new extension validation test)

Fixes #690. Fixes #597.

Copilot AI changed the title [WIP] Add documentation for supported config types Document supported config file extensions for --sqlconfig flag Jan 31, 2026
Copilot AI requested a review from dlevy-msft-sql January 31, 2026 20:00
@dlevy-msft-sql dlevy-msft-sql added bug Something isn't working Size: S Small issue (less than one week effort) needs-work labels Feb 1, 2026
Copy link
Copy Markdown

Copilot AI left a 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 addresses issue #597 by documenting the supported configuration file extensions for the --sqlconfig flag. Users were encountering "Unsupported Config Type" errors when using non-standard extensions like .sqlconfig without knowing which extensions are actually supported by Viper.

Changes:

  • Updated --sqlconfig flag help text to list supported extensions inline
  • Added comprehensive "Custom Configuration Files" section to README.md with examples
  • Regenerated translation catalogs for new localizable strings

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

File Description
cmd/modern/root.go Added inline documentation of supported extensions (.yaml, .yml, .json, .toml, .ini, .env, .properties) to the --sqlconfig flag help text
README.md Added new "Custom Configuration Files" section listing all supported extensions with format names, including variants and less common formats, plus usage examples and clarifying note about unsupported extensions
internal/translations/locales/*/out.gotext.json Regenerated translation catalogs with new help text string; non-English locales have empty translations awaiting human translation

Comment thread internal/translations/locales/de-DE/out.gotext.json
Copy link
Copy Markdown

Copilot AI left a 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 13 out of 14 changed files in this pull request and generated 3 comments.

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread internal/translations/locales/zh-CN/out.gotext.json
@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@copilot address the review comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 1, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • does
    • Triggering command: /tmp/go-build2543538777/b536/install.test /tmp/go-build2543538777/b536/install.test -test.testlogfile=/tmp/go-build2543538777/b536/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -I /tmp/net_C387458-ifaceassert x64/bin/go . oot}} {{.Goroot}-atomic --64 x64/bin/go -w -Wno-error -o/tmp/os_user_C-ifaceassert ux_amd64/vet -c oot}} {{.Goroot}-atomic /tmp/os_user_C18-bool ux_amd64/vet (dns block)
  • nonexistent.database.windows.net
    • Triggering command: /tmp/sqlcmd-e2e-847287666/sqlcmd /tmp/sqlcmd-e2e-847287666/sqlcmd -G -S nonexistent.database.windows.net -d testdb -compiler=gc ndor/bin/bash -installsuffix= oot}} {{.Goroot}-atomic -- hentication-libr-buildtags list�� -e store missing tr-ifaceassert ux_amd64/vet -installsuffix= mportPath}} {{.R-atomic -- ux_amd64/vet (dns block)
  • nonexistent.server
    • Triggering command: /tmp/sqlcmd-e2e-847287666/sqlcmd /tmp/sqlcmd-e2e-847287666/sqlcmd -S nonexistent.server -tests /tmp/go-build2543538777/b321/vet.cfg -e -compiler=gc ache/go/1.24.12/-nilfunc -installsuffix= oot}} {{.Goroot}-atomic -- nal/flags list�� -e store missing tr-ifaceassert ux_amd64/vet -installsuffix= mportPath}} {{.R-atomic -- ux_amd64/vet (dns block)
    • Triggering command: `/tmp/sqlcmd-e2e-847287666/sqlcmd /tmp/sqlcmd-e2e-847287666/sqlcmd -C -S nonexistent.server /tmp/go-build2543538777/b436/vet.cfg -I /tmp/os_user_C18-ifaceassert ache/go/1.24.12/-nilfunc . oot}}
      {{.Goroot}-test.testlogfile=/tmp/go-build3625500898/b001/testlog.txt --64 /v1.20.0 -W -I store missing translations

Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.norep-o ux_amd64/vet . mportPath}}
{{.R-atomic --64 ux_amd64/vet` (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown

Copilot AI left a 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 13 out of 13 changed files in this pull request and generated 3 comments.

Comment thread README.md Outdated
Comment thread cmd/modern/root.go Outdated
Comment thread README.md Outdated
@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@copilot fix the items in the review

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 1, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • does
    • Triggering command: /tmp/go-build3563136012/b536/install.test /tmp/go-build3563136012/b536/install.test -test.testlogfile=/tmp/go-build3563136012/b536/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ndLinux.slice -mtune=generic x64/bin/go (dns block)
  • nonexistent.database.windows.net
    • Triggering command: /tmp/sqlcmd-e2e-3521548478/sqlcmd /tmp/sqlcmd-e2e-3521548478/sqlcmd -G -S nonexistent.database.windows.net -d testdb (dns block)
  • nonexistent.server
    • Triggering command: /tmp/sqlcmd-e2e-3521548478/sqlcmd /tmp/sqlcmd-e2e-3521548478/sqlcmd -S nonexistent.server -tests /tmp/go-build3563136012/b455/vet.cfg ndLinux.slice 02160869 x64/bin/go sVt9gHpKW oot}} {{.Goroot}-atomic cal/bin/git x64/bin/go 0216�� log.showsignatur-errorsas log ux_amd64/compile-nilfunc -n1 oot}} {{.Goroot}-atomic ff25b1343cfc ux_amd64/compile-buildtags (dns block)
    • Triggering command: /tmp/sqlcmd-e2e-3521548478/sqlcmd /tmp/sqlcmd-e2e-3521548478/sqlcmd -C -S nonexistent.server /tmp/go-build3563136012/b417/vet.cfg --noprofile /home/REDACTED/go/pkg/mod/golang.org/x/text@v0.33.-f={{.Dir}} {{.ImportPath}} {{.R/tmp/go-build3563136012/b536/importcfg x64/bin/go (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Document supported config file extensions for --sqlconfig flag Document that --sqlconfig flag only supports YAML format Feb 1, 2026
Copy link
Copy Markdown

Copilot AI left a 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 13 out of 13 changed files in this pull request and generated no new comments.

@dlevy-msft-sql dlevy-msft-sql force-pushed the copilot/add-documentation-for-config-types branch from 0066869 to 77fffe6 Compare April 16, 2026 20:11
@dlevy-msft-sql dlevy-msft-sql changed the title Document that --sqlconfig flag only supports YAML format docs: document --sqlconfig YAML-only format requirement Apr 16, 2026
@dlevy-msft-sql dlevy-msft-sql changed the title docs: document --sqlconfig YAML-only format requirement fix: reject non-YAML extensions for --sqlconfig flag Apr 16, 2026
@dlevy-msft-sql dlevy-msft-sql force-pushed the copilot/add-documentation-for-config-types branch from 77fffe6 to 32948a1 Compare April 16, 2026 20:21
@dlevy-msft-sql dlevy-msft-sql force-pushed the copilot/add-documentation-for-config-types branch from 32948a1 to 3d689dd Compare April 16, 2026 20:25
@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

dlevy-msft-sql commented Apr 24, 2026

@copilot

Review finding: localization key mismatch

The Go code uses the string "configuration file (if named, must use .yaml or .yml extension)" for the --sqlconfig usage, but the catalog JSON key is "YAML configuration file (.yaml or .yml extension)". Since the keys don't match, the translation will never resolve -- the English fallback text displays correctly, but non-English locales will show the untranslated string.

Fix: Run gotext extract to regenerate the catalog, or update the Go string to match the existing catalog key.

@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@copilot

Review finding: localization key mismatch

The Go code uses the string "configuration file (if named, must use .yaml or .yml extension)" for the --sqlconfig usage, but the catalog JSON key is "YAML configuration file (.yaml or .yml extension)". Since the keys don't match, the translation will never resolve -- the English fallback text displays correctly, but non-English locales will show the untranslated string.

Fix: Run gotext extract to regenerate the catalog, or update the Go string to match the existing catalog key.

@copilot fix this

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 30, 2026

@copilot

Review finding: localization key mismatch
...

The localization keys are correctly aligned. The Go code in cmd/modern/root.go line 124 uses "YAML configuration file (.yaml or .yml extension)" which exactly matches the key in internal/translations/locales/*/out.gotext.json files and internal/translations/catalog.go line 349.

The empty translation fields in non-English locales are expected - they fall back to English until human translators provide translations. The localization system is working correctly as evidenced by testing with SQLCMD_LANG=de-DE showing the English fallback text.

@copilot

Review finding: localization key mismatch
...

No fix needed. The localization keys are already correctly matched between the Go code and translation files. Both use "YAML configuration file (.yaml or .yml extension)". The string mentioned in your comment "configuration file (if named, must use .yaml or .yml extension)" doesn't exist in the current codebase.

@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

@copilot rebase then check again

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 30, 2026

@copilot rebase then check again

Rebased onto latest main (commit a183f6c). Verified localization keys are correctly aligned after rebase:

Go code (cmd/modern/root.go:124): "YAML configuration file (.yaml or .yml extension)"
Translation files: All locales have matching key "YAML configuration file (.yaml or .yml extension)"
catalog.go (line 349): Key properly mapped

✅ Build passes
✅ Tests pass (internal/config)
✅ Help text displays correctly in both English and German locales

The branch is rebased but requires force-push permission to update remote. The localization system is working correctly with proper key alignment.

dlevy-msft-sql and others added 2 commits April 30, 2026 21:58
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>
@dlevy-msft-sql
Copy link
Copy Markdown
Contributor

Superseded by #747 (clean rewrite on current main without catalog churn or go.mod downgrades)

@dlevy-msft-sql dlevy-msft-sql deleted the copilot/add-documentation-for-config-types branch May 1, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Size: S Small issue (less than one week effort)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add validation/warning for unsupported config file extensions Add documentation/help about supported config types

3 participants