VerifiedPubSub.PayloadError exception (VerifiedPubSub v0.1.0)

Copy Markdown View Source

The error for a broadcast payload that does not match the shape that the manifest declares.

broadcast/4 and broadcast!/4 both raise it. A shape violation is a bug in the code of the caller, not a failure that the caller can expect. So {:error, _} only reports a transport failure, which a caller can handle.

The error reports every problem at once, not only the first:

invalid payload for :pets :adopted in MyApp.Topics:

  * missing required key: :id
  * unexpected key: :extra — not declared on this event
  * :name is declared as :string, got: 42

Summary

Types

A problem with a payload. Each value is one of these

t()

The fields of the error

Types

problem()

@type problem() ::
  {:not_a_map, term()}
  | {:struct_payload, module()}
  | {:missing, [atom()]}
  | {:unexpected, [atom()]}
  | {:type, atom(), VerifiedPubSub.Dsl.Field.type(), term()}

A problem with a payload. Each value is one of these:

  • {:not_a_map, value}: the payload is not a map.
  • {:struct_payload, module}: the payload is a struct of module, not a map.
  • {:missing, names}: the payload has no key for these required fields.
  • {:unexpected, names}: the payload has keys that the event does not declare.
  • {:type, name, type, value}: the value of the field name does not match type.

t()

@type t() :: %VerifiedPubSub.PayloadError{
  __exception__: term(),
  event: atom(),
  manifest: module(),
  payload: term(),
  problems: [problem()],
  topic: atom()
}

The fields of the error:

  • manifest: the manifest that declares the event.
  • topic: the name of the topic.
  • event: the event of the broadcast.
  • problems: every problem with the payload.
  • payload: the payload of the broadcast.