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

Editorial: correct command return values #350

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jugglinmike
Copy link
Contributor

@jugglinmike jugglinmike commented Jan 4, 2023

  • Editorial: correct command return value

    The "handle an incoming message" algorithm expects every command to return either a "success" value or an "error" value.

     1. Let |result| be the result of running the [=remote end steps=] for
        |command| given |session| and [=command parameters=]
        |matched|["<code>params</code>"]
    
    1. If |result| is an [=error=], then [=send an error response=] given
       |connection|, |command id|, and |result|'s [=error code=], and finally
       return.
    
    1. Let |value| be |result|'s data.
    

    Update the command algorithms to satisfy this expectation.

  • Editorial: return appropriate val. for EmptyResult

    The "handle an incoming message" algorithm asserts that values returned by command algorithms always match the documented type:

     1. Let |result| be the result of running the [=remote end steps=] for
        |command| given |session| and [=command parameters=]
        |matched|["<code>params</code>"]
    
    1. If |result| is an [=error=], then [=send an error response=] given
       |connection|, |command id|, and |result|'s [=error code=], and finally
       return.
    
    1. Let |value| be |result|'s data.
    
    1. Assert: |value| matches the definition for the [=result type=]
       corresponding to the command with [=command name=] |method|.
    

    However, some algorithms which are documented to return the EmptyResult type instead return null. Update those algorithms to return an empty map in order to satisfy the assertion.


Preview | Diff

The "handle an incoming message" algorithm asserts that values returned
by command algorithms always match the documented type:

>      1. Let |result| be the result of running the [=remote end steps=] for
>         |command| given |session| and [=command parameters=]
>         |matched|["<code>params</code>"]
>
>     1. If |result| is an [=error=], then [=send an error response=] given
>        |connection|, |command id|, and |result|'s [=error code=], and finally
>        return.
>
>     1. Let |value| be |result|'s data.
>
>     1. Assert: |value| matches the definition for the [=result type=]
>        corresponding to the command with [=command name=] |method|.

However, some algorithms which are documented to return the EmptyResult
type instead return null. Update those algorithms to return an empty
map in order to satisfy the assertion.
The "handle an incoming message" algorithm expects every command to
return either a "success" value or an "error" value.

>      1. Let |result| be the result of running the [=remote end steps=] for
>         |command| given |session| and [=command parameters=]
>         |matched|["<code>params</code>"]
>
>     1. If |result| is an [=error=], then [=send an error response=] given
>        |connection|, |command id|, and |result|'s [=error code=], and finally
>        return.
>
>     1. Let |value| be |result|'s data.

Update the command algorithms to satisfy this expectation.
@jgraham
Copy link
Member

jgraham commented Jan 4, 2023

I thought I'd already fixed this by allowing the top-level algorithm to handle null, but apparently not. In any case I prefer that fix to this one just because it's rather verbose to always have to return an empty map.

@jgraham
Copy link
Member

jgraham commented Jan 4, 2023

#351 is the alternative here.

@jugglinmike
Copy link
Contributor Author

I thought I'd already fixed this by allowing the top-level algorithm to handle null, but apparently not. In any case I prefer that fix to this one just because it's rather verbose to always have to return an empty map.

That makes the relevant commands just a little harder to interpret, since readers will have to learn that null is a special value which gets translated into something else.

There may be a middle ground, though--one that isn't quite as wordy as what I've suggested so far and which also preserves the direct relationship between the return value and the data sent to the local end. What about:

-1. Return [=success=] with data null.
+1. Return [=success=] with data set to an empty map.

@jgraham
Copy link
Member

jgraham commented Jan 6, 2023

I think I thought I'd fixed this because we fixed it in the original WebDriver spec.

I don't really mind either way between with data set to an empty map and with data null plus a special "null means an empty map" handling. The fact that no one really noticed for multiple years that the spec was broken, but nevertheless managed to come up with interoperable implementations suggests that the supposed difficulty reading it isn't much of a problem in practice.

In either case #351 now has a fix for the description of remote end steps incorrectly claiming that they return something matching the result production directly when in fact it's always a success or error value.

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