Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom class and message notices #359

Merged
merged 4 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/honeybadger/notice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,28 @@ defmodule Honeybadger.Notice do
new(%RuntimeError{message: message}, metadata, stacktrace, fingerprint)
end

def new(%{class: exception_name, message: message}, metadata, stacktrace, fingerprint)
when is_map(metadata) and is_list(stacktrace) do
new(exception_name, message, metadata, stacktrace, fingerprint)
end

def new(exception, metadata, stacktrace, fingerprint)
when is_map(metadata) and is_list(stacktrace) do
{exception, stacktrace} = Exception.blame(:error, exception, stacktrace)

%{__struct__: exception_mod} = exception

class = Utils.module_to_string(exception_mod)
message = exception_mod.message(exception)

new(class, message, metadata, stacktrace, fingerprint)
end

# bundles exception (or pseudo exception) information in to notice
defp new(class, message, metadata, stacktrace, fingerprint) do
error = %{
class: Utils.module_to_string(exception_mod),
message: exception_mod.message(exception),
class: class,
message: message,
backtrace: Backtrace.from_stacktrace(stacktrace),
tags: Map.get(metadata, :tags, []),
fingerprint: fingerprint
Expand Down
10 changes: 10 additions & 0 deletions test/honeybadger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ defmodule HoneybadgerTest do
assert_receive {:api_request, %{"error" => error}}
assert error["fingerprint"] == "fingerprint-xpto"
end

test "sending a notice with custom class and message" do
restart_with_config(exclude_envs: [])

Honeybadger.notify(%{class: "CustomError", message: "a message"})

assert_receive {:api_request, %{"error" => error}}
assert "CustomError" = error["class"]
assert "a message" = error["message"]
end
end

test "warn if incomplete env" do
Expand Down