smartrent / jackalope

An opinionated MQTT client library based on Tortoise MQTT
Apache License 2.0
28 stars 5 forks source link

Allow disabling JSON decoding #77

Closed ConnorRigby closed 2 years ago

ConnorRigby commented 2 years ago

GCP doesn't use JSON and upon connect, Jackalope crashes:

08:17:00.365 [error] GenServer {Tortoise311.Registry, {Tortoise311.Connection.Controller, "projects/keep-cloud-dev/locations/us-central1/registries/test-registry/devices/test-device"}} terminating
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    :erlang.iolist_to_binary(nil)
    (jason 1.2.2) lib/jason.ex:55: Jason.decode/2
    (jackalope 0.6.0) lib/jackalope/tortoise_handler.ex:54: Jackalope.TortoiseHandler.handle_message/3
    (tortoise311 0.11.3) lib/tortoise311/handler.ex:349: Tortoise311.Handler.execute/2
    (tortoise311 0.11.3) lib/tortoise311/connection/controller.ex:254: Tortoise311.Connection.Controller.handle_package/2
    (stdlib 3.17) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.17) gen_server.erl:771: :gen_server.handle_msg/6
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:incoming, <<50, 31, 0, 27, 47, 100, 101, 118, 105, 99, 101, 115, 47, 116, 101, 115, 116, 45, 100, 101, 118, 105, 99, 101, 47, 99, 111, 110, 102, 105, 103, 0, 1>>}}
State: %Tortoise311.Connection.Controller{awaiting: %{}, client_id: "projects/keep-cloud-dev/locations/us-central1/registries/test-registry/devices/test-device", handler: %Tortoise311.Handler{initial_args: [handler: GoogleCloudIotCore.TortoiseHandler, jackalope_pid: #PID<0.268.0>, last_will: nil], module: Jackalope.TortoiseHandler, state: %Jackalope.TortoiseHandler{default_last_will: nil, handler: GoogleCloudIotCore.TortoiseHandler, jackalope_pid: #PID<0.268.0>}}, ping: {[], []}, status: :up}
fhunleth commented 2 years ago

AWS IoT doesn't use JSON either. This depends on the software that you've written on the other side.

@jfcloutier It feels like we've talked about this and I don't remember the reasons for JSON encode/decode here. How about we drop the JSON encode/decode in Jackalope completely?

jfcloutier commented 2 years ago

@fhunleth Yes. I can see leaving payload encoding/decoding to Jackalope's client. No reason why not.