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

Validate options in dev mode #772

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

savhappy
Copy link
Collaborator

-validate all options passed to send_event even when in dev mode
-closes #766

Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

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

Left just a couple of comments but this is great.

lib/sentry.ex Outdated
@@ -335,7 +335,7 @@ defmodule Sentry do
Client.send_event(event, opts)

!Config.dsn() ->
:ignored
Client.validate_and_ignore(opts)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is gonna make it harder to track the return value–I have to jump to another module. Maybe we can do

Client.validate_options!(opts)
:ignored

instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good idea!

@@ -160,6 +160,12 @@ defmodule Sentry.Client do
end
end

@spec validate_and_ignore(keyword()) :: :ignored
def validate_and_ignore(opts) when is_list(opts) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can also re-use this function above where we call NimbleOptions.validate! if we change it to return the options, like suggested in the other comment.

Comment on lines 125 to 127
assert_raise(NimbleOptions.ValidationError, fn ->
Sentry.Client.validate_and_ignore(client: [bad_key: :nada])
end)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit:

Suggested change
assert_raise(NimbleOptions.ValidationError, fn ->
Sentry.Client.validate_and_ignore(client: [bad_key: :nada])
end)
assert_raise NimbleOptions.ValidationError, fn ->
Sentry.Client.validate_and_ignore(client: [bad_key: :nada])
end

Sentry.Client.validate_and_ignore(client: [bad_key: :nada])
end)

assert :ignored == Sentry.Client.validate_and_ignore(client: :hackney)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, but matches other tests:

Suggested change
assert :ignored == Sentry.Client.validate_and_ignore(client: :hackney)
assert :ignored = Sentry.Client.validate_and_ignore(client: :hackney)

@savhappy savhappy force-pushed the sav/validate-all-params-in-all-modes branch from 7653b87 to 01bf409 Compare August 19, 2024 14:19
@whatyouhide whatyouhide merged commit 50fcdbc into master Aug 19, 2024
4 checks passed
@whatyouhide whatyouhide deleted the sav/validate-all-params-in-all-modes branch August 19, 2024 16:33
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.

Validate all params passed to sentry even in dev/test
2 participants