zulip/zulip-flutter

Statically ensure that `UserTopicVisibilityPolicy.unknown` is not possible in our data models

Open

#1,074 创建于 2024年11月22日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Dart (456 fork)github user discovery
a-apihelp wanted

仓库指标

Star
 (454 star)
PR 合并指标
 (PR 指标待抓取)

描述

This was brought up here: https://github.com/zulip/zulip-flutter/pull/1041#discussion_r1853230302.

UserTopicVisibilityPolicy.unknown allows us to deserialize unknown enum values gracefully at the edge.

https://github.com/zulip/zulip-flutter/blob/9e42f2694afffd3a40c7ca4786e8641622513350/lib/model/channel.dart#L216-L222

https://github.com/zulip/zulip-flutter/blob/9e42f2694afffd3a40c7ca4786e8641622513350/lib/model/channel.dart#L348-L350

However, while we manually declare that it wouldn't be possible that we encounter UserTopicVisibilityPolicy.unknown when accessing our internal data store (i.e.: ChannelStore), our type doesn't agree with that, and require the UserTopicVisibilityPolicy.unknown case to be handled for an exhaustive switch. We use assert in such cases, but it is not supposed to be reachable (unless we have a bug).

We should make sure that such an assertion is not needed. To do this, we'll:

  • Remove unknown from UserTopicVisibilityPolicy.
  • In the places where it was needed, use a nullable type UserTopicVisibilityPolicy? instead.

Out of scope

This may or may not apply to other unknown enum values. It would be good to do a sweep of those and decide if we need to follow-up on them as well.

贡献者指南