Skip to content

fix: remove dropped formats from SupportedExts#2104

Open
veeceey wants to merge 2 commits intospf13:masterfrom
veeceey:fix/supported-exts-mismatch
Open

fix: remove dropped formats from SupportedExts#2104
veeceey wants to merge 2 commits intospf13:masterfrom
veeceey:fix/supported-exts-mismatch

Conversation

@veeceey
Copy link
Copy Markdown

@veeceey veeceey commented Feb 10, 2026

Summary

  • Remove HCL, Java Properties, and INI from SupportedExts — these formats were removed from core encoding in v1.20, but SupportedExts still listed them as "universally supported"
  • Update README to list only the built-in formats (JSON, TOML, YAML, Dotenv) and add a note pointing users to the upgrade guide for the removed formats
  • Update test that referenced hcl as a config type to use toml instead

Problem

Since v1.20 removed HCL, Java Properties, and INI from core encoding (DefaultCodecRegistry only supports JSON, TOML, YAML, Dotenv), having them in SupportedExts caused:

  1. Misleading file searches: searchInPath and findConfigFile iterated over SupportedExts looking for .hcl, .ini, .properties files that Viper cannot decode without a custom codec
  2. Confusing errors: The slices.Contains(SupportedExts, ...) validation passed for these formats, but the subsequent decoderRegistry.Decoder(format) call failed with a generic ConfigParseError instead of an UnsupportedConfigError
  3. Outdated documentation: The README still listed INI and "Java Propeties" [sic] as supported formats

Changes

File Change
viper.go Remove properties, props, prop, hcl, tfvars, ini from SupportedExts (both the var declaration and Reset())
viper.go Add doc comment explaining how to re-enable removed formats
README.md Update supported formats list; add note with link to upgrade guide
viper_test.go Change mismatch test from hcl to toml (still tests the same file-extension-takes-precedence behavior)

Backward compatibility

SupportedExts is an exported var that users can modify. Users who register custom codecs for HCL/INI/Properties via WithCodecRegistry will need to also append the corresponding extensions to SupportedExts. This is documented in the updated comment on the variable.

Test plan

  • All existing tests pass (go test ./...)
  • go vet ./... passes
  • Verify that config file search no longer looks for unsupported extensions
  • Verify that attempting to use a removed format produces UnsupportedConfigError instead of ConfigParseError

Fixes #2092

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 10, 2026

CLA assistant check
All committers have signed the CLA.

@sagikazarmark sagikazarmark added the kind/bug Something isn't working label Feb 18, 2026
@veeceey
Copy link
Copy Markdown
Author

veeceey commented Feb 20, 2026

CI is green across all platforms and Go versions except for one flaky TestWatchFile/file_content_changed failure on windows-latest with Go 1.24 (viper_bind_struct build tag). This is a pre-existing race condition in the file watcher test on Windows -- unrelated to the SupportedExts changes in this PR. The same test passes on the other Windows/Go combinations. Ready for review when you get a chance.

veeceey added 2 commits March 11, 2026 21:25
…dExts

Since v1.20, HCL, Java Properties, and INI were removed from core
encoding, but SupportedExts still listed them. This caused misleading
file searches (Viper looked for .hcl/.ini/.properties files it could
not decode) and confusing errors where format validation passed but
codec lookup failed with a generic ConfigParseError.

Update SupportedExts to only include formats with built-in codecs
(JSON, TOML, YAML, Dotenv). Users who register custom codecs for the
removed formats via WithCodecRegistry can append to SupportedExts.

Also update README to reflect the current supported formats and link
to the upgrade guide for the removed formats.

Fixes spf13#2092
On Windows, fsnotify may deliver the write event before the file content
is fully flushed, causing ReadInConfig to read stale data. Replace the
direct equality assertion with assert.Eventually to poll for the
expected value, giving the watcher time to pick up the final content.
@veeceey veeceey force-pushed the fix/supported-exts-mismatch branch from 4e005f6 to 2b35e17 Compare March 12, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outdated documentation for INI, HCL and Java Propeties

3 participants