Skip to content

Commit

Permalink
Better handling of the wrong config for messenger
Browse files Browse the repository at this point in the history
  • Loading branch information
am-kantox committed Dec 3, 2024
1 parent f23dac3 commit f2f097e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
7 changes: 4 additions & 3 deletions examples/tm/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config :telemetria,
events: [
[:tm, :f_to_c]
],
throttle: %{some_group: {1_000, :last}},
# create a slack app and put URL here
messenger_channels: %{slack: {:slack, url: ""}}
throttle: %{some_group: {1_000, :last}}

# create a slack app and put URL here
# messenger_channels: %{slack: {:slack, url: ""}}
29 changes: 29 additions & 0 deletions lib/telemetria/messenger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ defmodule Telemetria.Messenger do
else: inspect(message, opts)

do_post(message, impl, opts)
rescue
e in KeyError ->
require Logger

message =
"""
One or more required options were missing for the call to the messenger implementation
in `telemetría` module attribute (or global config.)
For now this is rescued and application can continue, but messenging from telemetria won’t work.
Error: #{e.message}.
"""

Logger.error(message)

e in RuntimeError ->
require Logger

message =
"""
The unexpected runtime error occured. Usually it means the config in `runtime.exs`
is diverged from what `telemetría` compliler saw. Please move all the config to the
compile-time configurations files since `telemetría` needs them during a compilation stage.
Error: #{e.message}
"""

Logger.error(message)
end

def post(message, impl, opts) when is_binary(message),
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Telemetria.MixProject do
use Mix.Project

@app :telemetria
@version "0.21.1"
@version "0.21.2"

def project do
[
Expand Down

0 comments on commit f2f097e

Please sign in to comment.