@@ -147,7 +147,7 @@ def build_subsection(
147147
148148 collapsible = Collapsible (* widgets , title = title , collapsed = collapsed )
149149 elif tui_style == "roofline" :
150- if dfs ["roofline " ]:
150+ if dfs ["4. Roofline " ]:
151151 widget = RooflinePlot (dfs )
152152 collapsible = Collapsible (widget , title = title , collapsed = collapsed )
153153 else :
@@ -172,28 +172,89 @@ def build_dynamic_kernel_sections(
172172) -> List [Collapsible ]:
173173 children = []
174174
175+ def add_warning (message : str ):
176+ children .append (Label (message , classes = "warning" ))
177+
178+ def validate_data_structure (data , name : str , parent_name : str = None ) -> bool :
179+ if data is None :
180+ location = f"'{ parent_name } ' > '{ name } '" if parent_name else f"'{ name } '"
181+ add_warning (f"Analysis result for { location } is not available" )
182+ return False
183+
184+ if not isinstance (data , dict ):
185+ location = f"'{ parent_name } ' > '{ name } '" if parent_name else f"'{ name } '"
186+ add_warning (
187+ f"Analysis result for { location } is not a dictionary type: { type (data )} "
188+ )
189+ return False
190+
191+ return True
192+
193+ def create_safe_widget (subsection_name : str , data : dict , section_name : str ):
194+ if not (isinstance (data , dict ) and "df" in data ):
195+ add_warning (
196+ f"Invalid data structure for '{ subsection_name } ' in section '{ section_name } '"
197+ )
198+ return None
199+
200+ try :
201+ df = data ["df" ]
202+ tui_style = data .get ("tui_style" )
203+ widget = create_widget_from_data (df , tui_style )
204+
205+ if widget is None :
206+ add_warning (f"Widget creation returned None for '{ subsection_name } '" )
207+ return None
208+
209+ return widget
210+ except Exception as e :
211+ add_warning (f"Failed to create widget for '{ subsection_name } ': { str (e )} " )
212+ return None
213+
214+ def create_safe_collapsible (widget , title ):
215+ try :
216+ return Collapsible (widget , title = title , collapsed = True )
217+ except Exception as e :
218+ add_warning (f"Failed to create collapsible for '{ title } ': { str (e )} " )
219+ return None
220+
175221 try :
222+ if not validate_data_structure (dfs , "analysis result" ):
223+ return children
224+
176225 for section_name , subsections in dfs .items ():
177226 if section_name in skip_sections :
178227 continue
179228
229+ if not validate_data_structure (subsections , section_name ):
230+ continue
231+
180232 kernel_children = []
181233 for subsection_name , data in subsections .items ():
182- if isinstance (data , dict ) and "df" in data :
183- df = data ["df" ]
184- tui_style = data .get ("tui_style" )
185- widget = create_widget_from_data (df , tui_style )
186- kernel_children .append (
187- Collapsible (widget , title = subsection_name , collapsed = True )
234+ try :
235+ widget = create_safe_widget (subsection_name , data , section_name )
236+ if widget :
237+ collapsible = create_safe_collapsible (widget , subsection_name )
238+ if collapsible :
239+ kernel_children .append (collapsible )
240+ except Exception as e :
241+ add_warning (
242+ f"Error processing subsection '{ subsection_name } ' in section '{ section_name } ': { str (e )} "
188243 )
189244
190245 if kernel_children :
191- children .append (
192- Collapsible (* kernel_children , title = section_name , collapsed = True )
193- )
246+ try :
247+ section_collapsible = Collapsible (
248+ * kernel_children , title = section_name , collapsed = True
249+ )
250+ children .append (section_collapsible )
251+ except Exception as e :
252+ add_warning (
253+ f"Failed to create collapsible for section '{ section_name } ': { str (e )} "
254+ )
194255
195256 except Exception as e :
196- children . append ( Label ( f"Error in Kernel Section: { str (e )} ", classes = "error" ) )
257+ add_warning ( f"Unexpected error in Kernel Section processing : { str (e )} " )
197258
198259 return children
199260
0 commit comments