From 3d68e394dcf0893adf00918ef5d431f326fcfe22 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 9 Dec 2018 17:31:06 +0000 Subject: [PATCH] bots: Raise KeyError inside storage.get(). Our bots rely on get() raising `KeyError` if a key does not exist. This was a regression in this commit: https://github.com/zulip/python-zulip-api/commit/d7d2f6bbd6e25f4247fb13ff0c113b05c4197ea8 --- zulip_bots/zulip_bots/bots/incident/incident.py | 4 ++-- zulip_bots/zulip_bots/lib.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/incident/incident.py b/zulip_bots/zulip_bots/bots/incident/incident.py index 05f50d5..fde3b6f 100644 --- a/zulip_bots/zulip_bots/bots/incident/incident.py +++ b/zulip_bots/zulip_bots/bots/incident/incident.py @@ -2,7 +2,7 @@ import html import json import random import re -from zulip_bots.lib import Any, StateHandlerError +from zulip_bots.lib import Any from typing import Optional, Any, Dict, Tuple @@ -79,7 +79,7 @@ def parse_answer(query: str) -> Tuple[str, str]: def generate_ticket_id(storage: Any) -> str: try: incident_num = storage.get('ticket_id') - except (StateHandlerError, KeyError): + except (KeyError): incident_num = 0 incident_num += 1 incident_num = incident_num % (1000) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index d934aca..b8f2ed0 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -72,7 +72,7 @@ class StateHandler(object): response = self._client.get_storage({'keys': [key]}) if response['result'] != 'success': - raise StateHandlerError("Error fetching state: {}".format(str(response))) + raise KeyError('key not found: ' + key) marshalled_value = response['storage'][key] self.state_[key] = marshalled_value