Skip to content

Change MLLP.Ack to return always return a two element tuple #36

@starbelly

Description

@starbelly

Currently, MLLP.Ack returns the follow when verifying per the follow spec :

 @type ack_verification_result ::
            {:ok, atom(), MLLP.Ack.t()}
            | {:error, atom(), MLLP.Ack.t()}
            | {:error, :bad_ack_code, String.t()}
            | {:error, :bad_message_control_id, String.t()}
            | {:error, :invalid_message, String.t()}
            | {:error, :invalid_ack_message, String.t()}

I think what would be more ergonomic is return a two element tuple. Either an ok tuple or an error tuple.

Specifically, I think it would be advantageous to always return {:ok, %Ack{}} or {:error, Ack{}} and simply put the error code (that's currently the second element) in the Ack struct and always put the ack message in the Ack tuple (currently can be the third element in a return).

So in the case of say an invalid ack message {:error, %Ack{error: :invalid_ack_message}}

Doing so would allow us in MLLP.Client to always return a two element tuple for the sake of consistency, then it's up to the caller to match on the error code in the struct, etc. if they so choose.

Edit:

Note if we want to send a better signal for matching purposes, an idea might be to have two or three structs, Ack, Nack, and AckError, something along those lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions