Skip to content

Conversation

@zephyrean
Copy link

@zephyrean zephyrean commented Nov 24, 2025

This PR addresses several Dialyzer warnings and logical issues.

Changes:

  1. Fix has_missing_options/2 logic

    • Switched from lists:dropwhile/2 to lists:filter/2.
    • Previously, dropwhile would stop at the first present option, potentially ignoring missing options later in the list and returning options that are actually present
  2. Improve error propagation in validators

    • Updated map_validator, map_dynamic_validator, list_validator, tuple_validator, and tuple_dynamic_validator
    • Add catch-all pattern to handle {no_validator, ...} and other possible return values
    • This fixes a potential case_clause crash when a nested validator returns errors other than simple invalidation (e.g., {no_validator, ...}, {missing_options, ...}).
  3. map_validator: validate fields option type and add more tests

    • check that fields option is a list and add a catch-all clause
      to return {invalid_option_value, not_list} preventing a crash
    • add tests for map_validator
      • missing mandatory options
      • invalid/unknown options
      • invalid option values (non-list fields)
      • handling of unknown validators in fields

The function could report present options as missing: it stopped at
the first missing option and returned it with the rest of the list
which could contain options that are actually present.
Previously, validators would crash on {no_validator, _} or {invalid_options, _}
tuples because the case clause only expected {invalid, _} or valid.
- Add `is_list(Fields)` guard to `map_validator:validate/3`.
- Add a catch-all clause to return `{invalid_option_value, not_list}`
  if the `fields` option is not a list, preventing a crash.
- Add tests for map_validator:
  - missing mandatory options
  - invalid/Unknown options
  - invalid option values (non-list fields)
  - handling of unknown validators in fields
@zephyrean zephyrean force-pushed the fix/validation-logic-and-dialyzer branch from 0e7e320 to 7d06a24 Compare November 24, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant