Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typespec for KafkaEx.Protocol.Produce.Message with optional :timestamp #480

Open
esambo opened this issue Mar 4, 2023 · 0 comments
Open

Comments

@esambo
Copy link

esambo commented Mar 4, 2023

I am getting some typespec errors because Dialyzer doesn't like Message{timestamp: nil}. This timestamp was added as a required key. Shouldn't it be optional, so that it can be skipped as in the compression example, and not produce any dialyzer errors?

alias KafkaEx.Protocol.Produce.{Message, Request}
@type kafka_response ::
        nil
        | :ok
        | {:ok, integer()}
        | {:error, :closed}
        | {:error, :inet.posix()}
        | {:error, any()}
        | iodata()
        | :leader_not_available

@spec test :: kafka_response()
def test do
  %Message{
    key: "ID 1", value: "payload" #, timestamp: 666 # <== required to fix dialyzer error
  }
  |> produce_on_kafka()
end

@spec produce_on_kafka(Message.t()) :: kafka_response()
def produce_on_kafka(%Message{} = message) do
  %Request{
    topic: "test_topic",
    messages: [message]
  }
  |> KafkaEx.produce()
end
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

No branches or pull requests

1 participant