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:
d7d2f6bbd6
This commit is contained in:
parent
f191d44992
commit
3d68e394dc
|
@ -2,7 +2,7 @@ import html
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from zulip_bots.lib import Any, StateHandlerError
|
from zulip_bots.lib import Any
|
||||||
|
|
||||||
from typing import Optional, Any, Dict, Tuple
|
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:
|
def generate_ticket_id(storage: Any) -> str:
|
||||||
try:
|
try:
|
||||||
incident_num = storage.get('ticket_id')
|
incident_num = storage.get('ticket_id')
|
||||||
except (StateHandlerError, KeyError):
|
except (KeyError):
|
||||||
incident_num = 0
|
incident_num = 0
|
||||||
incident_num += 1
|
incident_num += 1
|
||||||
incident_num = incident_num % (1000)
|
incident_num = incident_num % (1000)
|
||||||
|
|
|
@ -72,7 +72,7 @@ class StateHandler(object):
|
||||||
|
|
||||||
response = self._client.get_storage({'keys': [key]})
|
response = self._client.get_storage({'keys': [key]})
|
||||||
if response['result'] != 'success':
|
if response['result'] != 'success':
|
||||||
raise StateHandlerError("Error fetching state: {}".format(str(response)))
|
raise KeyError('key not found: ' + key)
|
||||||
|
|
||||||
marshalled_value = response['storage'][key]
|
marshalled_value = response['storage'][key]
|
||||||
self.state_[key] = marshalled_value
|
self.state_[key] = marshalled_value
|
||||||
|
|
Loading…
Reference in a new issue