Bylaw.Ecto.Query.Issue (bylaw_ecto_query v0.1.0-alpha.1)

Copy Markdown View Source

Describes a query validation issue found by a check.

Summary

Functions

Formats a query issue for human-readable error output.

Formats a query issue for human-readable error output.

Formats many query issues for human-readable error output.

Formats many query issues for human-readable error output.

Types

format_opt()

@type format_opt() :: {:meta, boolean()}

format_opts()

@type format_opts() :: [format_opt()]

t()

@type t() :: %Bylaw.Ecto.Query.Issue{
  check: module(),
  message: String.t(),
  meta: map()
}

Functions

format(issue)

@spec format(t()) :: String.t()

Formats a query issue for human-readable error output.

Metadata is omitted by default because issue messages are meant for humans and often already contain the actionable details. Pass meta: true to include the structured metadata for debugging.

Examples

iex> issue = %Bylaw.Ecto.Query.Issue{
...>   check: MyApp.RequiredOrder,
...>   message: "queries with limit require order_by",
...>   meta: %{operation: :all}
...> }
iex> Bylaw.Ecto.Query.Issue.format(issue)
"MyApp.RequiredOrder: queries with limit require order_by"

iex> issue = %Bylaw.Ecto.Query.Issue{
...>   check: MyApp.RequiredOrder,
...>   message: "queries with limit require order_by",
...>   meta: %{operation: :all}
...> }
iex> Bylaw.Ecto.Query.Issue.format(issue, meta: true)
"MyApp.RequiredOrder: queries with limit require order_by %{operation: :all}"

format(issue, opts)

@spec format(t(), format_opts()) :: String.t()

Formats a query issue for human-readable error output.

format_many(issues)

@spec format_many([t()]) :: String.t()

Formats many query issues for human-readable error output.

Examples

iex> issues = [
...>   %Bylaw.Ecto.Query.Issue{check: MyApp.RequiredOrder, message: "missing order"},
...>   %Bylaw.Ecto.Query.Issue{check: MyApp.EmptyInPredicates, message: "empty in predicate"}
...> ]
iex> Bylaw.Ecto.Query.Issue.format_many(issues)
"MyApp.RequiredOrder: missing order\nMyApp.EmptyInPredicates: empty in predicate"

format_many(issues, opts)

@spec format_many([t()], format_opts()) :: String.t()

Formats many query issues for human-readable error output.