     pos = Farmbot.BotState.get_current_pos
 
     # take logger time stamp and spit out a unix timestamp for the javascripts.
-    with {:ok, created_at} <- parse_created_at(timestamp) do
-      thing =
-        build_log(message, created_at, type, channels, pos)
-      build_rpc(thing) |> @rpc_transport.emit
-      dispatch({messages ++ [thing], posting?})
-    end || dispatch({messages, posting?})
+    with {:ok, created_at} <- parse_created_at(timestamp),
+         {:ok, log} <- build_log(message, created_at, type, channels, pos),
+         {:ok, json} <- build_rpc(log),
+         # ^ This will possible return nil if it cant create json.
+         # it will silently be discarded.
+         :ok <- @rpc_transport.emit(json),
+         # make sure we add the non json version of the log message.
+         do: dispatch({messages ++ [log], posting?})
+    # if we got nil before, dont dispatch the new message into the buffer
+    || dispatch({messages, posting?})
   end
 
   def handle_event(:flush, state) do

defmodule Farmbot.Logger do
  @moduledoc """
    Logger backend for logging to the frontend and dumping to the API.
  """
  @rpc_transport Application.get_env(:json_rpc, :transport)
  use GenEvent
  alias RPC.Spec.Notification, as: Notification

  # I SUCK
  def handle_event(thing, Farmbot.Logger), do: handle_event(thing, build_state)

  # Posts an array of logs to the API.
  @spec do_post([log_message],pid) :: :ok
  defp do_post(m, pid) do
    case to_json(m) do
      nil ->
        # THis shouldn't happen but if it does, i dont know what shoulg happen.
        # Problem: somewhere in the list of log messages, there is a
        # message that can not be turned to json.
        # meaning that next time this function comes rount, it
        # still won't be able to make it json.
        send(pid, :post_complete)
      {:ok, messages} ->
        Farmbot.HTTP.post("/api/logs", messages) |> parse_resp(pid)
    end
  end

