Fail in Config#chunkOf If Data Is Missing #7690
Merged
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.
At least to me it seems strange that the following code succeeds with an empty chunk.
This code doesn't even really make sense because the
ConfigProvider.fromMap
and in fact any flatConfigProvider
consists of key value pairs and theConfig
is attempting to load a value without specifying a key. So there is no conceivable input forConfig.fromMap
in which this would load any information.Even when we do specify a configuration that makes sense here, we get what I think are somewhat counterintuitive results:
This is definitely debatable but it seems questionable whether we should be succeeding with an empty chunk if the key doesn't exist. In particular, it seems inconsistent that attempting to load a chunk in a map where the key doesn't exist succeeds with an empty chunk but attempting to load something else like a string in a map where the key doesn't exist will fail. You could say that the chunk has a natural "empty" element which other types don't but I think we need consistent behavior across data types.
So I would expect
a
to fail with aConfig.Error
instead of succeeding with an empty chunk.This PR changes this behavior so that the first example and
a
both fail. So you can still have empty sequences but you at least need the key to be present. If you want the current behavior of succeeding with an empty chunk if the key is not present you could dochunkOf("key", Config.string).withDefault(Chunk.empty)
.