Skip to content

Commit 2966fc9

Browse files
committed
Adjusting the exception handling mechanism
1 parent fd89acd commit 2966fc9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

modelcache/adapter/adapter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def cache_data_convert(cache_data, cache_query):
2121
**kwargs
2222
)
2323
except Exception as e:
24-
return 'adapt_query_exception'
25-
24+
return str(e)
2625

2726
@classmethod
2827
def create_insert(cls, *args, **kwargs):
@@ -32,9 +31,7 @@ def create_insert(cls, *args, **kwargs):
3231
**kwargs
3332
)
3433
except Exception as e:
35-
logging.info('adapt_insert_e: {}'.format(e))
36-
return 'adapt_insert_exception'
37-
34+
return str(e)
3835

3936
@classmethod
4037
def create_remove(cls, *args, **kwargs):
@@ -45,7 +42,7 @@ def create_remove(cls, *args, **kwargs):
4542
)
4643
except Exception as e:
4744
logging.info('adapt_remove_e: {}'.format(e))
48-
return 'adapt_remove_exception'
45+
return str(e)
4946

5047

5148
def construct_resp_from_cache(return_message, return_query):

modelcache/adapter/adapter_remove.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from modelcache import cache
3-
from modelcache.utils.error import NotInitError
3+
from modelcache.utils.error import NotInitError, RemoveError
44

55

66
def adapt_remove(*args, **kwargs):
@@ -17,11 +17,10 @@ def adapt_remove(*args, **kwargs):
1717
if remove_type == 'delete_by_id':
1818
id_list = kwargs.pop("id_list", [])
1919
resp = chat_cache.data_manager.delete(id_list, model=model)
20-
2120
elif remove_type == 'truncate_by_model':
2221
resp = chat_cache.data_manager.truncate(model)
23-
2422
else:
25-
resp = "remove_type_error"
23+
# resp = "remove_type_error"
24+
raise RemoveError()
2625
return resp
2726

modelcache/utils/error.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ def __init__(self):
99
super().__init__("The cache should be inited before using")
1010

1111

12+
class RemoveError(CacheError):
13+
"""Raise when the cache has been used before it's inited"""
14+
def __init__(self):
15+
super().__init__("The cache remove error")
16+
1217
class NotFoundError(CacheError):
1318
"""Raise when getting an unsupported store."""
1419
def __init__(self, store_type, current_type_name):

0 commit comments

Comments
 (0)