Right, I understand. I'd argue that many times there isn't much more to say 
beyond 'We require this option, please provide it'. Also, a simple way of 
ensuring the options are there would be very useful when prototyping, as it 
would prevent from `nil`s sneaking deep into the logic, before friendly 
error messages are added. 
środa, 28 sierpnia 2024 o 17:50:08 UTC+2 José Valim napisał(a):

> We considered this but the error we would raise is generic. It is much 
> better for you to validate afterwards and raise good error messages that 
> say it is missing and which value you should pass instead and what it is 
> used for!
>
> On Wed, Aug 28, 2024 at 11:30 Mateusz Front <mateus...@swmansion.com> 
> wrote:
>
>> Hi,
>>
>> WDYT about adding a `strict: boolean` option to `Keyword.validate/2` that 
>> would make it return an error if a key that doesn't have a default value 
>> provided is absent? The returned value in case of an error could be 
>> `{:error, unknown_keys, missing_keys}`, for example:
>>
>> {:error, [], [:b]} = Keyword.validate([a: :foo], [:a, :b], strict: true)
>> {:error, [:c], [:b]} = Keyword.validate([a: :foo, c: :bar], [:a, :b], 
>> strict: true)
>> {:error, [:c], []} = Keyword.validate([a: :foo, b: :foobar, c: :bar], [:a, 
>> :b], strict: true)
>>
>> in case of success, the result would remain as it is now:
>>
>> {:ok, [a: :foo, b: :bar]} = Keyword.validate([a: :foo, b: :bar], [:a, :b], 
>> strict: true)
>> {:ok, [b: :bar, a: :foo]} = Keyword.validate([a: :foo], [:a, b: :bar], 
>> strict: true)
>>
>> The behaviour would be unchanged when the strict is set to false 
>> (default). The bang version would be adjusted accordingly.
>>
>> Thanks ;)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/44d14235-d129-4f1c-b9de-7895c610d083n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/44d14235-d129-4f1c-b9de-7895c610d083n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/97f43ae7-0d4a-4ef8-9a73-e8275f9b9b06n%40googlegroups.com.

Reply via email to