Repository: streamlit/streamlit
File: lib/streamlit/runtime/app_session.py (Python)

Code before:
    )
    if enum_value is None:
        allowed_values = ", ".join(k.lower() for k in Config.ToolbarMode.keys())  # noqa: SIM118
        raise ValueError(
            f"Config {config_key!r} expects to have one of "
            f"the following values: {allowed_values}. "
            f"Current value: {config_value}"
        )
    return enum_value


def _get_show_error_links() -> Config.ShowErrorLinks.ValueType:
    config_key = "client.showErrorLinks"
    config_value = config.get_option(config_key)
    enum_name = f"SHOW_ERROR_LINKS_{config_value.upper()}"
    enum_value: Config.ShowErrorLinks.ValueType | None = getattr(
        Config.ShowErrorLinks, enum_name, None
    )
    if enum_value is None:
        allowed_values = ", ".join(
            k.replace("SHOW_ERROR_LINKS_", "").lower()
            for k in Config.ShowErrorLinks.keys()  # noqa: SIM118
        )
        raise ValueError(
            f"Config {config_key!r} expects to have one of "
            f"the following values: {allowed_values}. "
            f"Current value: {config_value}"
        )
    return enum_value


def _populate_config_msg(msg: Config) -> None:
    msg.gather_usage_stats = config.get_option("browser.gatherUsageStats")
    msg.max_cached_message_age = config.get_option("global.maxCachedMessageAge")
    msg.allow_run_on_save = config.get_option("server.allowRunOnSave")
    msg.hide_top_bar = config.get_option("ui.hideTopBar")
    if config.get_option("client.showSidebarNavigation") is False:
        msg.hide_sidebar_nav = True
    msg.toolbar_mode = _get_toolbar_mode()
    msg.show_error_links = _get_show_error_links()


def _populate_theme_msg(msg: CustomThemeConfig, section: str = "theme") -> None:
    theme_opts = config.get_options_for_section(section)
    if all(val is None for val in theme_opts.values()):
        return

    for option_name, option_val in theme_opts.items():
        # We need to ignore some config options here that need special handling
        # and cannot directly be set on the protobuf.
        if (

Review comment (suggestion):
[suggestion: non-blocking] I guess we can keep this code like this, I see this follows the `_get_toolbar_mode` pattern above. It seems like the intention is to not have to keep a list of valid config options in sync with the proto enum. I am not sure how often we would be adding enum values to make this a big concern though. It would be easier to read if we just had something like this ... 

```
allowed_values = ["auto", "true", "false"]
config_value = config.get_option("client.showErrorLinks")
if config_value not in allowed_values:
   ... error

map_to_enum = {
"auto" : Config.ShowErrorLinks.SHOW_ERROR_LINKS_AUTO,
...
}

return map_to_enum.get(config_value)

```

Not blocking, since we are doing this above. 

Code after:
            page_proto.url_pathname = page_info["page_name"]
            page_proto.icon = page_info["icon"]


# Config.ToolbarMode.ValueType does not exist at runtime (only in the pyi stubs), so
# we need to use quotes.
# This field will be available at runtime as of protobuf 3.20.1, but
# we are using an older version.
# For details, see: https://github.com/protocolbuffers/protobuf/issues/8175
def _get_toolbar_mode() -> Config.ToolbarMode.ValueType:
    config_key = "client.toolbarMode"
    config_value = config.get_option(config_key)
    enum_value: Config.ToolbarMode.ValueType | None = getattr(
        Config.ToolbarMode, config_value.upper()
    )
    if enum_value is None:
        allowed_values = ", ".join(k.lower() for k in Config.ToolbarMode.keys())  # noqa: SIM118
        raise ValueError(
            f"Config {config_key!r} expects to have one of "
            f"the following values: {allowed_values}. "
            f"Current value: {config_value}"
        )
    return enum_value


def _get_show_error_links() -> Config.ShowErrorLinks.ValueType:
    config_key = "client.showErrorLinks"
    allowed_values = ["auto", "true", "false"]
    value_to_enum = {
        "auto": Config.ShowErrorLinks.SHOW_ERROR_LINKS_AUTO,
        "true": Config.ShowErrorLinks.SHOW_ERROR_LINKS_TRUE,
        "false": Config.ShowErrorLinks.SHOW_ERROR_LINKS_FALSE,
    }
    config_value = config.get_option(config_key)
    if config_value not in allowed_values:
        raise ValueError(
            f"Config {config_key!r} expects to have one of "
            f"the following values: {', '.join(allowed_values)}. "
            f"Current value: {config_value}"
        )
    return value_to_enum[config_value]


def _populate_config_msg(msg: Config) -> None:
    msg.gather_usage_stats = config.get_option("browser.gatherUsageStats")
    msg.max_cached_message_age = config.get_option("global.maxCachedMessageAge")
    msg.allow_run_on_save = config.get_option("server.allowRunOnSave")
    msg.hide_top_bar = config.get_option("ui.hideTopBar")
    if config.get_option("client.showSidebarNavigation") is False:
        msg.hide_sidebar_nav = True
    msg.toolbar_mode = _get_toolbar_mode()