Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

module Jason is not available #350

@jay-meister

Description

@jay-meister

I get this error intermittently in a test:

:gen_event handler Logger.Backends.Console installed in Logger terminating
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function Jason.encode!/2 is undefined (module Jason is not available)
        (jason) Jason.encode!(%{context: %{runtime: %{application: :ev2, file: "lib/ev2/lib/sign/sign_api.ex", function: "new_envelope/3", line: 90, module_name: "Ev2.Lib.SignAPI", vm_pid: "<0.7745.0>"}, system: %{hostname: "Jacks-MacBook-Pro", pid: 96869}}, dt: "2019-09-19T14:26:34.320308Z", error: "{:error, %HTTPoison.Response{body: \"{\\\"loginAccounts\\\":[{\\\"baseUrl\\\":\\\"oh_yeah\\\"}]}\", headers: %{}, request: nil, request_url: nil, status_code: 201}}", level: :error, message: "docusign.envelope.new.request_error"}, [escape: :json])
        (timber) lib/timber/formatter.ex:73: Timber.Formatter.format/4
        (logger) lib/logger/backends/console.ex:186: Logger.Backends.Console.format_event/5
        (logger) lib/logger/backends/console.ex:140: Logger.Backends.Console.log_event/5
        (logger) lib/logger/backends/console.ex:45: Logger.Backends.Console.handle_event/2
        (stdlib) gen_event.erl:577: :gen_event.server_update/4
        (stdlib) gen_event.erl:559: :gen_event.server_notify/4
        (stdlib) gen_event.erl:300: :gen_event.handle_msg/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

It only intermittently errors once in this test for my entire testing suite.

I am currently using timber-elixir and timber-elixir-plug.

I think I can see that timber-elixir-phoenix has a configurable :json_library https://github.com/timberio/timber-elixir-phoenix/blob/master/config/config.exs#L23

But can't see that in the timber-elixir-plug https://github.com/timberio/timber-elixir-plug/blob/master/config/config.exs

The code:

      case HTTPoison.post(url, Jason.encode!(body), headers, recv_timeout: 40_000) do 
          {:ok,
           %HTTPoison.Response{
             body: res_body,
             headers: headers,
             request: %{body: req_body, headers: _req_headers},
             status_code: status_code
           }} ->
            res_body = Jason.decode!(res_body)

            Logger.error(fn ->
              {"docusign.envelope.new.failure",
               event: %{
                 response: %{
                   status_code: status_code,
                   body: res_body,
                   headers: headers,
                   request: %{body: Jason.decode!(req_body)}
                 }
               }}
            end)

            {:error, "docusign.envelope.new.failure - #{res_body["errorCode"]} (#{status_code})"}

My setup:

I've recently upgraded to Phoenix 1.4 and have removed Poison and included Jason.
mix.exs:

  defp deps do
    [
      {:phoenix, "~> 1.4.0"},
      {:plug, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:httpoison, "~> 1.0"},
      {:appsignal, "~> 1.0"},
      {:jason, "~> 1.0"},
      {:timber, "~> 3.0"},
      {:timber_plug, "~> 1.0"}
    ]
  end

config.exs

# Configure timber as logger
config :logger, :console,
  format: {Timber.Formatter, :format},
  metadata: :all

# Define json library for phoenix
config :phoenix, :json_library, Jason

test.exs

# Print only warnings and errors during test
config :logger, level: :warn

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