@@ -36,18 +36,25 @@ def _sync_wrapper(*args, **kwargs) -> Any:
3636 _decorator_log_count += 1
3737 result = func (* args , ** kwargs )
3838 success = True
39- if tool_name == "manage_script" and kwargs .get ("action" ) == "create" :
40- record_milestone (MilestoneType .FIRST_SCRIPT_CREATION )
41- elif tool_name .startswith ("manage_scene" ):
42- record_milestone (MilestoneType .FIRST_SCENE_MODIFICATION )
43- record_milestone (MilestoneType .FIRST_TOOL_USAGE )
39+ action_val = sub_action or kwargs .get ("action" )
40+ try :
41+ if tool_name == "manage_script" and action_val == "create" :
42+ record_milestone (MilestoneType .FIRST_SCRIPT_CREATION )
43+ elif tool_name .startswith ("manage_scene" ):
44+ record_milestone (MilestoneType .FIRST_SCENE_MODIFICATION )
45+ record_milestone (MilestoneType .FIRST_TOOL_USAGE )
46+ except Exception :
47+ _log .debug ("milestone emit failed" , exc_info = True )
4448 return result
4549 except Exception as e :
4650 error = str (e )
4751 raise
4852 finally :
4953 duration_ms = (time .time () - start_time ) * 1000
50- record_tool_usage (tool_name , success , duration_ms , error , sub_action = sub_action )
54+ try :
55+ record_tool_usage (tool_name , success , duration_ms , error , sub_action = sub_action )
56+ except Exception :
57+ _log .debug ("record_tool_usage failed" , exc_info = True )
5158
5259 @functools .wraps (func )
5360 async def _async_wrapper (* args , ** kwargs ) -> Any :
@@ -70,18 +77,25 @@ async def _async_wrapper(*args, **kwargs) -> Any:
7077 _decorator_log_count += 1
7178 result = await func (* args , ** kwargs )
7279 success = True
73- if tool_name == "manage_script" and kwargs .get ("action" ) == "create" :
74- record_milestone (MilestoneType .FIRST_SCRIPT_CREATION )
75- elif tool_name .startswith ("manage_scene" ):
76- record_milestone (MilestoneType .FIRST_SCENE_MODIFICATION )
77- record_milestone (MilestoneType .FIRST_TOOL_USAGE )
80+ action_val = sub_action or kwargs .get ("action" )
81+ try :
82+ if tool_name == "manage_script" and action_val == "create" :
83+ record_milestone (MilestoneType .FIRST_SCRIPT_CREATION )
84+ elif tool_name .startswith ("manage_scene" ):
85+ record_milestone (MilestoneType .FIRST_SCENE_MODIFICATION )
86+ record_milestone (MilestoneType .FIRST_TOOL_USAGE )
87+ except Exception :
88+ _log .debug ("milestone emit failed" , exc_info = True )
7889 return result
7990 except Exception as e :
8091 error = str (e )
8192 raise
8293 finally :
8394 duration_ms = (time .time () - start_time ) * 1000
84- record_tool_usage (tool_name , success , duration_ms , error , sub_action = sub_action )
95+ try :
96+ record_tool_usage (tool_name , success , duration_ms , error , sub_action = sub_action )
97+ except Exception :
98+ _log .debug ("record_tool_usage failed" , exc_info = True )
8599
86100 return _async_wrapper if inspect .iscoroutinefunction (func ) else _sync_wrapper
87101 return decorator
0 commit comments