-
Notifications
You must be signed in to change notification settings - Fork 14
Labels
kind/enhancementImprovements to existing feature.Improvements to existing feature.
Milestone
Description
When setting up a config provider hierarchy, you might treat config files as optional - read them if they're there, but ignore if they're missing. This allows a nice linear setup like this:
let config = ConfigReader(providers: [
EnvironmentVariablesProvider(),
JSONProvider(filePath: "config.json")
])The above will throw an error if config.json is missing, so today you need to handle it manually with:
var providers: [any ConfigProvider] = [
EnvironmentVariablesProvider()
]
if FileManager.default.fileExists(atPath: "config.json") {
providers.append(JSONProvider(filePath: "config.json"))
}
let config = ConfigReader(providers: providers)While not the end of the world, the verbosity and the repeating of the path makes this slightly painful.
Do we want to change the file providers to instead handle missing files gracefully, for example using an optional flag in the initializer that specifies the behavior?
let config = ConfigReader(providers: [
EnvironmentVariablesProvider(),
JSONProvider(filePath: "config.json", isRequired: true), // will throw if file is missing or malformed
JSONProvider(filePath: "optional-config.json", isRequired: false), // will become an empty provider if file is missing or malformed
])We'd still default isRequired: Bool = true, but folks can make it more graceful by setting it to false.
Opinions?
tkrajacic and sebsto
Metadata
Metadata
Assignees
Labels
kind/enhancementImprovements to existing feature.Improvements to existing feature.