Skip to content

Do not raise exception when decoding packets #119

Open
@wojtekmach

Description

@wojtekmach

It crashes the connection:

iex(1)> {:ok, pid} = MyXQL.start_link([]); MyXQL.query!(pid, "SELECT TIME(ADDTIME('23:00:00', '02:00:00'))")
** (ArgumentError) cannot decode "1d 01:00:00" as time, negative or >= 24:00:00 values are not supported
    (myxql 0.4.2) lib/myxql/protocol/values.ex:511: MyXQL.Protocol.Values.time/6
    (myxql 0.4.2) lib/myxql/protocol/values.ex:481: MyXQL.Protocol.Values.decode_time/4
    (myxql 0.4.2) lib/myxql/protocol.ex:539: MyXQL.Protocol.decode_resultset/4
    (myxql 0.4.2) lib/myxql/client.ex:197: MyXQL.Client.recv_packets/6
    (myxql 0.4.2) lib/myxql/connection.ex:102: MyXQL.Connection.handle_execute/4
    (db_connection 2.2.1) lib/db_connection/holder.ex:316: DBConnection.Holder.holder_apply/4
    (db_connection 2.2.1) lib/db_connection.ex:1255: DBConnection.run_execute/5
    (db_connection 2.2.1) lib/db_connection.ex:1342: DBConnection.run/6
    (db_connection 2.2.1) lib/db_connection.ex:539: DBConnection.parsed_prepare_execute/5
    (db_connection 2.2.1) lib/db_connection.ex:532: DBConnection.prepare_execute/4
    (myxql 0.4.2) lib/myxql.ex:235: MyXQL.do_query/4
    (myxql 0.4.2) lib/myxql.ex:258: MyXQL.query!/4
iex(1)>
19:47:44.063 [error] GenServer #PID<0.217.0> terminating
** (DBConnection.ConnectionError) client #PID<0.213.0> stopped: ** (ArgumentError) cannot decode "1d 01:00:00" as time, negative or >= 24:00:00 values are not supported

Instead we should return an error tuple and later decide what to do with it.

We may still want to disconnect because if we stop decoding in the middle, there might be still data on the socket which may or may not be a problem.

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