dashbitco / nimble_options

A tiny library for validating and documenting high-level options. 💽
Apache License 2.0
507 stars 38 forks source link

A question on error message of `validate/2` #127

Closed c4710n closed 5 months ago

c4710n commented 5 months ago

When trying the example code in README.md:

definition = [
  connections: [
    type: :non_neg_integer,
    default: 5
  ],
  url: [
    type: :string,
    required: true
  ]
]

options = []
NimbleOptions.validate(options, definition)

It returns:

{:error,
 %NimbleOptions.ValidationError{
   message: "required :url option not found, received options: [:connections]",
   key: :url,
   value: nil,
   keys_path: []
 }}

We provide options as [],

But, the message: line shows that the received options are [:connections].


It seems that the received options considers the default values, but should we consider the default values when showing the received options?

josevalim commented 5 months ago

Yes, looks like a bug to me! PRs welcome!