Skip to content

Conversation

mitchellhenke
Copy link
Contributor

Current implementation causes this warning because we're checking a compile-time module attribute at runtime, so the result is always the same. Looks like this:

  warning: this check/guard will always yield the same result
    lib/sentry/event.ex:195

Not super familiar with metaprogramming stuff, but this defines a macro that will either find and insert the source code context or return the frame as-is and remove the warning.

{pre_context, context, post_context} =
Sentry.Sources.get_source_context(@source_files, file, line_number)
@spec macro_put_source_context(map(), String.t(), integer()) :: map()
def macro_put_source_context(frame, file, line_number) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this private and rename it to "do_put_source_context" instead of macro. Its pretty common.

else
frame
end
Map.put(frame, :context_line, context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start this with frame |>

@mitchellhenke
Copy link
Contributor Author

@jeregrine updated 🙂

do_put_source_context(unquote(frame), unquote(file), unquote(line_number))
end
else
frame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to quote this?

@mitchellhenke
Copy link
Contributor Author

@jeregrine updated 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants