fix: remove dropped formats from SupportedExts#2104
Open
veeceey wants to merge 2 commits intospf13:masterfrom
Open
fix: remove dropped formats from SupportedExts#2104veeceey wants to merge 2 commits intospf13:masterfrom
veeceey wants to merge 2 commits intospf13:masterfrom
Conversation
Author
|
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. |
…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.
4e005f6 to
2b35e17
Compare
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.
Summary
SupportedExts— these formats were removed from core encoding in v1.20, butSupportedExtsstill listed them as "universally supported"hclas a config type to usetomlinsteadProblem
Since v1.20 removed HCL, Java Properties, and INI from core encoding (
DefaultCodecRegistryonly supports JSON, TOML, YAML, Dotenv), having them inSupportedExtscaused:searchInPathandfindConfigFileiterated overSupportedExtslooking for.hcl,.ini,.propertiesfiles that Viper cannot decode without a custom codecslices.Contains(SupportedExts, ...)validation passed for these formats, but the subsequentdecoderRegistry.Decoder(format)call failed with a genericConfigParseErrorinstead of anUnsupportedConfigErrorChanges
viper.goproperties,props,prop,hcl,tfvars,inifromSupportedExts(both the var declaration andReset())viper.goREADME.mdviper_test.gohcltotoml(still tests the same file-extension-takes-precedence behavior)Backward compatibility
SupportedExtsis an exportedvarthat users can modify. Users who register custom codecs for HCL/INI/Properties viaWithCodecRegistrywill need to also append the corresponding extensions toSupportedExts. This is documented in the updated comment on the variable.Test plan
go test ./...)go vet ./...passesUnsupportedConfigErrorinstead ofConfigParseErrorFixes #2092