Ash.Type.CompositeTypeHelpers (ash v3.37.2)

Copy Markdown View Source

Shared utilities for the composite types: maps, keyword lists, structs, tuples and typed structs.

Typed structs use this module to convert their validation errors. The other documented error formatters are no longer used by the composite types and remain for compatibility. The functions that cast, dump, load and check declared fields are internal.

Summary

Functions

Converts constraint errors to keyword list format, ensuring each error has a :field key set to the specified field name.

Converts validation errors from composite types to InvalidAttribute exceptions.

Filters out non-informative constraint errors.

Formats a single constraint error as a comprehensive keyword list.

Functions

convert_constraint_errors_to_keyword_lists(errors, field)

Converts constraint errors to keyword list format, ensuring each error has a :field key set to the specified field name.

convert_errors_to_invalid_attributes(error)

Converts validation errors from composite types to InvalidAttribute exceptions.

Handles multiple error formats:

  • Single keyword list errors
  • Lists of keyword list errors and exceptions; exceptions pass through
  • Other error formats (passed through to Ash.Error.to_ash_error)

Keyword list errors keep their :path.

For backward compatibility with typed_struct.ex, returns a single error for single error lists, and multiple errors for multiple error lists.

filter_non_informative_errors(errors)

Filters out non-informative constraint errors.

Removes constraint key-value pairs that don't provide meaningful error messages to users.

format_comprehensive_error_as_keyword(error, field)

Formats a single constraint error as a comprehensive keyword list.

Keeps the error's own :field if it has one and sets field otherwise.