Page MenuHomePhorge

Improve handling queries with "Current Viewer" set while not logged in
AbandonedPublic

Authored by aklapper on Jan 4 2024, 11:39.
Tags
None
Referenced Files
F2187553: D25505.1715499256.diff
Sat, May 11, 07:34
Unknown Object (File)
Sat, May 4, 15:52
Unknown Object (File)
Sat, May 4, 15:22
Unknown Object (File)
Sat, May 4, 14:55
Unknown Object (File)
Thu, May 2, 17:01
Unknown Object (File)
Thu, May 2, 16:24
Unknown Object (File)
Thu, May 2, 10:38
Unknown Object (File)
Sat, Apr 27, 00:17

Details

Summary

Avoid exposing a cryptic exception and instead show an explanatory error message to the user by allowing error handling for PhabricatorTypeaheadInvalidTokenException in PhabricatorApplicationSearchController instead of PhabricatorTypeaheadDatasource.

Yes, hardcoding names of child classes is ugly. Better ideas welcome.

Test Plan

Create an advanced Maniphest query with "Closed By" set to "Current Viewer" and access the resulting URL while not logged in.

Fixes T15704

Diff Detail

Repository
rP Phorge
Branch
T15704typeaheadException (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1002
Build 1002: arc lint + arc unit

Event Timeline

aklapper requested review of this revision.Jan 4 2024, 11:39
20after4 subscribed.

Is this needed simply because PhabricatorApplicationSearchController doesn't actually have a try { } block to catch this particular case? Maybe we could improve the exception handling instead of return null?

I guess I'm fine with this though, since I haven't dug into the details I'm not sure if there is a better solution. The behavior is undeniably improved though so I'm leaning towards accepting it despite the hard coded class name string.

This revision is now accepted and ready to land.Jan 5 2024, 02:07

Is this needed simply because PhabricatorApplicationSearchController doesn't actually have a try { } block to catch this particular case? Maybe we could improve the exception handling instead of return null?

Not sure I can follow, there is a try block at https://we.phorge.it/source/phorge/browse/master/src/applications/search/controller/PhabricatorApplicationSearchController.php$246-348 which also catches PhabricatorTypeaheadInvalidTokenException. I don't know why PhabricatorTypeaheadDatasource.php "overwrites" the error handling for PhabricatorTypeaheadInvalidTokenException in PhabricatorApplicationSearchController though.

How about other functions that might require a logged-in user? "current Viewer's Projects" for example?

the simplest other-solution would be to extract the exception thrown to its own method, and override that method in the child-class:

if !(allow_partial) {
  $this->throwInvalidTokenForNonPartial($function);
}

...

protected function throwInvalidTokenForNonPartial($function) {
      throw new PhabricatorTypeaheadInvalidTokenException(
          pht(
            'This datasource ("%s") can not evaluate the function "%s(...)".',
            get_class($this),
            $function));
}

and then have PhabricatorPeopleUserFunctionDatasource override it with a new exception class, and catch that exception somewhere and convert to a nicer error message...

ok, that doesn't sound "simplest" now :)

Alternatively, maybe catch the existing exception and show a nice error message + the form?

How about other functions that might require a logged-in user? "current Viewer's Projects" for example?

Same Unhandled Exception behavior as described in this ticket for git master and same "Query Errors / Invalid Function: viewer()" behavior with my branch applied.

Let's visually mark this to attract people.

Side note: I've not found any way to "check if a function exists, but it's just not available" so to allow throw a more suitable exception, and eventually catch just that.

This revision now requires changes to proceed.Feb 28 2024, 12:31

Alternatively, maybe catch the existing exception and show a nice error message + the form?

IIUC that's what the current patch is doing - see the screenshots in T15704#14922. But it does so by hardcoding a specific class...

This single-casing of a specific class is not ideal, but given the complexity of other proposals here I'd like to get the current four lines in. Any other opinions? :)

I'm currently stuck on this since I'm trying to refactor the functions to support an indications about "I work for everybody" and "I work for only logged-in users" to be able to distinguish the case "The token exists" VS "The token exists but it's not visible" VS "The token does not exist"

I think this is part of the maximum efforts minimum results team. Sorry if I cannot share further help but I think this would be a good refactor, if somebody starts such a stub.

Thanks again for this patch that highlighted the valley and the mountain in a very clear way.

maybe catch the existing exception and show a nice error message + the form?

Something like this? (incomplete, but it starts providing a more specific exception):

D25621

The approach taken in D25621 is more wholesome and preferable thus abandoning this