Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_error(self):
client = self.make_client([b'ERROR\r\n'])
def _get():
client.get(b'key')
pytest.raises(MemcacheUnknownCommandError, _get)
spans = self.check_spans(1, ['get'], ['get key'])
self.assertEqual(spans[0].error, 1)
def _raise_errors(self, line, name):
if line.startswith(b'ERROR'):
raise MemcacheUnknownCommandError(name)
if line.startswith(b'CLIENT_ERROR'):
error = line[line.find(b' ') + 1:]
raise MemcacheClientError(error)
if line.startswith(b'SERVER_ERROR'):
error = line[line.find(b' ') + 1:]
raise MemcacheServerError(error)
# try to set relevant tags, catch any exceptions so we don't mess
# with the application
try:
span.set_tags(p.tags)
vals = _get_query_string(args)
query = '{}{}{}'.format(method_name, ' ' if vals else '', vals)
span.set_tag(memcachedx.QUERY, query)
except Exception:
log.debug('Error setting relevant pymemcache tags')
try:
return method(*args, **kwargs)
except (
MemcacheClientError,
MemcacheServerError,
MemcacheUnknownCommandError,
MemcacheUnknownError,
MemcacheIllegalInputError,
):
(typ, val, tb) = sys.exc_info()
span.set_exc_info(typ, val, tb)
reraise(typ, val, tb)