Page MenuHomePhabricator

Investigate: How to implement error handling for similar users api call [8H]
Closed, ResolvedPublic

Description

T296296: Fetch information from the similar_users API sets up the api call but only returns data when successful. We should provide useful errors in cases where it fails (eg. unauthorized, no results).

This investigation should answer the following questions:

  • Which errors can we encounter?
  • How should we implement error handling?

@Prtksxna @Niharika We may ask you to review the errors and decide how much information we should relay to the user about each one, and what any error messages should say

Related Objects

Event Timeline

Tchanders renamed this task from Implement error handling for similar users api call to Investigate: How to implement error handling for similar users api call [8H].May 20 2022, 4:39 PM
Tchanders updated the task description. (Show Details)
Tchanders added a subscriber: Niharika.
How to display errors

We can display errors by altering this:

$response = $this->httpRequestFactory->get($this->apiUrl.'?usertext='.$editor,[
	'username' => $this->apiUser,
	'password' => $this->apiPassword
], __METHOD__ );
if ( $response ) {
	$json = json_decode( $response, true );
	if ( $json ) {
		// Return array of Neighbors

To something like this:

$request = $this->httpRequestFactory->create($this->apiUrl.'?usertext='.$editor,[
	'username' => $this->apiUser,
	'password' => $this->apiPassword
], __METHOD__ );
$status = $request->execute();

Which allows us to check $status->isOK(). Most of the error messages below are accessible via $request->getContent(), if we decide to display them.

What errors can occur

@Prtksxna Would it be possible to make mockups for an error state? The errors we can get back from the Similarusers get_similar_users endpoint are summarised below. What should we communicate to the user in each case? I'm imagining that the user might want to see details about the errors that can occur on successful form submission, as well as timeout errors and the database refresh error. But probably not errors caused by software bugs (these are logged, so we can look them up).

ProblemMessageOccurrenceFootnoteWhat can the user do
Max neighbours to return not givenNo k specified (422)Could only be caused by a bug in Similarusers1Nothing until software fixed
User to query not givenNo usertext provided (422)Could only be caused by a bug in SimilarEditors1Nothing until software fixed
User to query is empty"missing user_text -- e.g., \"Isaac (WMF)\" for https://en.wikipedia.org/wiki/User:Isaac_(WMF)"Could only be caused by a bug in SimilarEditors2Nothing until software fixed
User has contributions but no account"User <username> does not appear to have an account in English Wikipedia."Could occur with valid form submission (though shouldn't be reachable)2Nothing
User name is for a bot account"User <username> is a bot and therefore out of scope."Could occur with a valid form submission2Nothing
User does not have an account or has no edits"User <username> does not appear to have an account (or edits in scope) in English Wikipedia."Could occur with a valid form submission2Nothing
Similarusers is unavailable when the database is being refreshed"Database refresh in progress" (403)Happens once a month2Try again later
Any error encountered when looking up user in similar-users database(undetermined, many possibilities)Presumably caused by bugs in Similarusers stack2Probably nothing until software fixed
Any error encountered when querying enwiki for edits since the last database dumps"Failed to get additional edits for user <username>"Presumably caused by bugs in Similarusers stack2Probably nothing until software fixed
Similarusers timed out(generic message that doesn't indicate timeout)Usually due to Similarusers making too many API requests when a user has a lot of recent edits - see T307023#79608383Nothing

Footnotes

[1] These error messages are returned by Flask's abort method and aren't easily accessible. They are embedded within HTML snippets that need to be parsed. (As an improvement, we could update Similarusers to return a Flask Response object instead.)
[2] We receive these error messages in full
[3] We may have to do some work to determine when there was a timeout and displaying something helpful

@Tchanders and I discussed that we need to categorize the error states a bit more:

  • How likely is the user to see this error?
  • Can they recover from the error? How?
  • Is there information that they'd need to share with us for debugging purposes?

We also talked about the display of error messages:

  • Form validation errors will stay where they are
  • Other errors will show up above the form box
    • We'll continue to show the form below the error and not have a separate page just to show errors

Screen Shot 2022-06-03 at 10.36.54 AM.png (850×1 px, 67 KB)

How likely is the user to see this error?

It's hard to say anything other than the obvious - I don't particularly expect lots of software bugs, but there may well be users out there with too few or too many edits

Can they recover from the error? How?

I've added another column for this - basically no, except for the database refresh error

Is there information that they'd need to share with us for debugging purposes?

I don't think it's necessary - we should have enough info in the error logs.

Thanks for the mockup. If you could provide some copy for the messages then I'll file a follow-up task.

Thanks @Tchanders. Wanted to confirm that the time out error (last one in the table) isn't recoverable and trying again later won't help.

Working on the messages now and will share them soon.

Thanks @Tchanders. Wanted to confirm that the time out error (last one in the table) isn't recoverable and trying again later won't help.

Working on the messages now and will share them soon.

Yes, it's not recoverable and is related to the users being searched and how active they are, so trying again soon after won't help.

Thanks for the mockup. If you could provide some copy for the messages then I'll file a follow-up task.

Error number (as per order in table)Message
1, 2, 3, 8, 9, 10Something has gone wrong, we’re looking into it. If the problem persists please reach out to us here.
4, 5, 6Message as given in table
7Something has gone wrong, please try again in a few minutes.