If a JSON encoder is not defined, sending an Airbrake notice can crash your app.
We removed poison as a dependency in one of our apps and did not set :json_encoder in the config for :airbrake_client. The code compiled fine and everything worked fine until Airbrake.Worker tried to JSON encode the payload. Since :json_encoder was not set, Airbrake.Worker tried using Poison, but since that had been removed as a dependency, there was no module for JSON encoding. Airbrake.Worker threw an exception which caused its process to crash, and subsequently caused the whole app to crash.
It's a silent failure unless you happen to be watching the logs or if you monitor the state of your app (which is probably a good idea anyway).
This PR tries to solve two problems:
Alert the developer that there is no module for a JSON encoder.
Don't crash if the JSON encoder does not have an encode!/1 function.
If :json_encoder is not set and poison is not a dependency, airbrake_client will compile with a warning. This is pretty weak, but it's was the best I could do with my meta-programming skills.
If :json_encoderis not set andpoisonis not a dependency,airbrake_clientwill not start and so will prevent your app from starting. The check is inAirbrake.Worker.init/1`.
If a module for a JSON encoder is available but it does not define encode!/1, there will be a runtime error to stderr (not using the logger) and a very simple Airbrake notice about the missing encode!/1will be sent. The Airbrake.Worker process will not crash.
If a JSON encoder is not defined, sending an Airbrake notice can crash your app.
We removed
poison
as a dependency in one of our apps and did not set:json_encoder
in theconfig
for:airbrake_client
. The code compiled fine and everything worked fine untilAirbrake.Worker
tried to JSON encode the payload. Since:json_encoder
was not set,Airbrake.Worker
tried usingPoison
, but since that had been removed as a dependency, there was no module for JSON encoding.Airbrake.Worker
threw an exception which caused its process to crash, and subsequently caused the whole app to crash.It's a silent failure unless you happen to be watching the logs or if you monitor the state of your app (which is probably a good idea anyway).
This PR tries to solve two problems:
encode!/1
function.If
:json_encoder
is not set andpoison
is not a dependency,airbrake_client
will compile with a warning. This is pretty weak, but it's was the best I could do with my meta-programming skills.If :json_encoder
is not set and
poisonis not a dependency,
airbrake_clientwill not start and so will prevent your app from starting. The check is in
Airbrake.Worker.init/1`.If a module for a JSON encoder is available but it does not define
encode!/1
, there will be a runtime error to stderr (not using the logger) and a very simple Airbrake notice about the missingencode!/1
will be sent. TheAirbrake.Worker
process will not crash.