1111# limitations under the License.
1212
1313import importlib .util
14+ import logging
1415import sys
1516from typing import List , Optional , Tuple
1617
1718from fs_api .driver import FSProcessorDriver
1819
20+ logger = logging .getLogger (__name__ )
21+
1922from .store .fs_context import WitContext , convert_config_to_dict
2023
2124
@@ -46,11 +49,13 @@ def fs_exec(class_name: str, modules: List[Tuple[str, bytes]]) -> None:
4649 # Create the module
4750 module = importlib .util .module_from_spec (spec )
4851
49- # Execute the module source code
50- # Note: exec is required here for dynamic module loading
51- # This is a controlled execution environment for user-provided code
52+ # Execute the module source code.
53+ # exec is required: importlib.util.module_from_spec does not execute
54+ # code; Python's import system uses exec internally. This runtime
55+ # is designed to execute trusted user-provided processor code in
56+ # an isolated WASM sandbox. Only deploy code from trusted sources.
5257 code = compile (module_source , f"<{ module_name } >" , "exec" )
53- exec (code , module .__dict__ ) # noqa: S102
58+ exec (code , module .__dict__ ) # noqa: S102 # nosec B102
5459
5560 # Add the module to sys.modules
5661 sys .modules [module_name ] = module
@@ -105,47 +110,44 @@ def fs_init(self, config: List[Tuple[str, str]]) -> None:
105110 if _DRIVER :
106111 try :
107112 _DRIVER .init (_CONTEXT , _CONTEXT ._CONFIG )
108- except Exception :
109- # Silently ignore initialization errors to allow graceful degradation
110- pass # noqa: S110
113+ except Exception as e :
114+ logger .debug ("Driver init failed (graceful degradation): %s" , e )
111115
112116 def fs_process (self , source_id : int , data : bytes ) -> None :
113117 if not _DRIVER or not _CONTEXT :
114118 return
115119
116120 try :
117121 _DRIVER .process (_CONTEXT , source_id , data )
118- except Exception :
119- # Silently ignore processing errors to allow graceful degradation
120- pass # noqa: S110
122+ except Exception as e :
123+ logger .debug ("Process error (graceful degradation): %s" , e )
121124
122125 def fs_process_watermark (self , source_id : int , watermark : int ) -> None :
123126 if not _DRIVER or not _CONTEXT :
124127 return
125128
126129 try :
127130 _DRIVER .process_watermark (_CONTEXT , source_id , watermark )
128- except Exception :
129- # Silently ignore watermark processing errors to allow graceful degradation
130- pass # noqa: S110
131+ except Exception as e :
132+ logger .debug ("Watermark process error (graceful degradation): %s" , e )
131133
132134 def fs_take_checkpoint (self , checkpoint_id : int ) -> None :
133135 if not _DRIVER or not _CONTEXT :
134136 return
135137
136138 try :
137139 _DRIVER .take_checkpoint (_CONTEXT , checkpoint_id )
138- except Exception :
139- # Silently ignore checkpoint errors to allow graceful degradation
140- pass # noqa: S110
140+ except Exception as e :
141+ logger .debug ("Checkpoint error (graceful degradation): %s" , e )
141142
142143 def fs_check_heartbeat (self ) -> bool :
143144 if not _DRIVER or not _CONTEXT :
144145 return False
145146
146147 try :
147148 return _DRIVER .check_heartbeat (_CONTEXT )
148- except Exception :
149+ except Exception as e :
150+ logger .debug ("Heartbeat check failed (graceful degradation): %s" , e )
149151 return False
150152
151153 def fs_close (self ) -> None :
@@ -154,9 +156,8 @@ def fs_close(self) -> None:
154156 if _DRIVER and _CONTEXT :
155157 try :
156158 _DRIVER .close (_CONTEXT )
157- except Exception :
158- # Silently ignore close errors to ensure cleanup completes
159- pass # noqa: S110
159+ except Exception as e :
160+ logger .debug ("Driver close error (cleanup continues): %s" , e )
160161
161162 _DRIVER = None
162163 _CONTEXT = None
0 commit comments