Skip to content

Conversation

@gnprice
Copy link
Member

@gnprice gnprice commented Mar 25, 2022

This should completely eliminate errors of the form "Unhandled Zulip API event type", so that when they show up again it's because of some new event type added on the server.

It also gives us a bit more of an inventory of what's needed for #3408. (Though really the main part of that task is events that we already know exist and just don't completely handle, and this doesn't affect those.)

gnprice added 2 commits March 24, 2022 17:15
Awkwardly this actually requires the cases to use string literals
directly, rather than the named constants.  I prefer named constants
for the sake of greppability... but when required to choose, checking
for errors is more important.

The fact that Flow passes after this change means that the `switch` is
covering all the event types our API code knows about.  There are a
number of others the server can send, though.  Next we'll add all of
those to the list, and explicitly call out the ones we're ignoring.
@gnprice gnprice added the a-data-sync Zulip's event system, event queues, staleness/liveness label Mar 25, 2022
gnprice added 2 commits March 24, 2022 17:42
With comments about in what circumstances we'll need to start
handling them.

Generated the list automatically from the API metadata, like so:

  $ python -c 'if 1:
        import yaml, json, sys
        z = yaml.safe_load(open("../zulip/zerver/openapi/zulip.yaml"))
        json.dump(z, sys.stdout)
      ' | jq '
        .paths["/events"].get.responses["200"].content["application/json"]
          .schema.allOf[2].properties.events.items.oneOf
          [] | ((.properties // .allOf[1].properties).type.allOf[1].enum[0] // .)
      ' -r \
    | sort -u \
    | perl -lne 'print "  $_: null,"'

(That `jq` formula is a bit brittle to the details of how our
openapi/zulip.yaml is written.  If you're trying it in the future and
that has changed in a way that breaks this, the `// .` should cause
the whole objects affected to get spit out.  In that case, delete the
`| sort -u` to see more clearly for debugging.)
These were never documented, were never needed for mobile, and
are now obsolete.  But for the moment we still support servers
that send them, so we want to explicitly ignore them.
Copy link
Contributor

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM, merging.


case EventTypes.restart:
case EventTypes.stream:
case 'restart':
Copy link
Contributor

Choose a reason for hiding this comment

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

Awkwardly this actually requires the cases to use string literals
directly, rather than the named constants. I prefer named constants
for the sake of greppability... but when required to choose, checking
for errors is more important.

Huh, yeah. Even this doesn't seem to work:

    case (EventTypes.restart: 'restart'):

Shrug, ah, well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. :-/

@chrisbobbe chrisbobbe merged commit 9cf0765 into zulip:main Mar 25, 2022
@gnprice gnprice deleted the pr-event-types branch March 25, 2022 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a-data-sync Zulip's event system, event queues, staleness/liveness

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants