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

Clearer error messages when editing actions #7359

Closed
wants to merge 4 commits into from

Conversation

neilkakkar
Copy link
Contributor

@neilkakkar neilkakkar commented Nov 25, 2021

Changes

Return better error messages when creating actions with invalid selectors.

This creates 2 toasts: one for events querying, another for action counts. It's not deterministic which toast "wins", hence putting the error message in both place.

Unsure if there's a better way to handle this 👀

Before:

image

image

After:

image

How did you test this code?

Run locally

@neilkakkar neilkakkar changed the title WIP: Testing regression changes Clearer error messages when editing actions Nov 25, 2021
@neilkakkar neilkakkar marked this pull request as ready for review November 25, 2021 12:48
@neilkakkar neilkakkar requested a review from Twixes November 25, 2021 12:49
Copy link
Contributor

@paolodamico paolodamico left a comment

Choose a reason for hiding this comment

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

Love that we're improving this, added some comments inline.

@@ -17,6 +21,9 @@ def wrap_query_error(err: Exception) -> Exception:

# :TRICKY: Return a custom class for every code by looking up the short name and creating a class dynamically.
if hasattr(err, "code"):
if err.code == 427:
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this 427 come from? Maybe add a comment on how CH handles this and why we raise it this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, this is the error coming from CH, whose name is CHQueryErrorCannotCompileRegexp , which occurs when the regex being passed in is invalid.

@@ -5,6 +5,10 @@
from posthog.exceptions import EstimatedQueryExecutionTimeTooLong


class CHQueryErrorCannotCompileRegexp(ServerException):
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to be using this for multiple cases, not sure if the name reflects the right use for this. I would also suggest adding a useful default code & message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically for capturing the error CH sends to us. So, using the same name as the CH error code, to prevent confusion.

The error message we raise is ValidationError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's always a code and message generated from CH, so we shouldn't need to supply even a default one ourselves.

"SELECT count(1) FROM events WHERE team_id = %(team_id)s AND {}".format(query),
{"team_id": action.team_id, **params},
)
except CHQueryErrorCannotCompileRegexp:
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to comment above, but why do we raise a Regexp compile error here? Is the only error that happen here related to a regex error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There can be several errors when querying CH (see the file above where I define this for the rest of them - all 500 of them), and this on is specific to the user input being provided for selectors / regexes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the only error that happen here related to a regex error?

Yes

@macobo
Copy link
Contributor

macobo commented Nov 26, 2021

Not a fan that this "swallows" legit errors and these won't reach sentry. This in turn means we won't ever discover or fix issues relating to bad selector complication (most of these are not user errors).

If we wanted to do validation, this would be better handled in the action creation api as validation instead. Or better yet, in the frontend similar to #4680

query_result = self._query_events_list(filter, team, request, limit=limit)
except CHQueryErrorCannotCompileRegexp:
raise ValidationError(
"Invalid filter for events. Check that your selectors and regexes are defined properly."
Copy link
Contributor

Choose a reason for hiding this comment

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

This is misleading - we fail to compile legit selectors on our end. This is not an user error.

@neilkakkar
Copy link
Contributor Author

Nice, that route is much better, closing this.

@neilkakkar neilkakkar closed this Nov 26, 2021
@paolodamico paolodamico deleted the fix-selector-matching branch November 29, 2021 16:28
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.

3 participants