From 2d866a0fb5738868b9674c672f0ea6775b764a56 Mon Sep 17 00:00:00 2001 From: Vitali Graf Date: Sat, 27 Dec 2025 17:28:04 +0100 Subject: [PATCH] =?UTF-8?q?Code-Qualit=C3=A4t:=20Robustere=20Fehlerbehandl?= =?UTF-8?q?ung=20in=20MainWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verbessert die Fehlerbehandlung und Code-Robustheit durch: - Explizite bool()-Konvertierung für has_xml_files (Zeile 894) - Frühere Initialisierung von pdf_basename für Exception-Handler (Zeile 3717) - Null-Checks für self.project/project_dir mit Fallback-Logik (Zeile 3741) Verhindert potenzielle AttributeError und UnboundLocalError. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/ui/MainWindow.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ui/MainWindow.py b/src/ui/MainWindow.py index 58cfb05..16a984d 100644 --- a/src/ui/MainWindow.py +++ b/src/ui/MainWindow.py @@ -891,7 +891,7 @@ class MainWindow(QMainWindow): # Transformations-Aktionen (nur aktiv wenn XML-Dateien vorhanden) tree_node_obj = item.data(0, Qt.ItemDataRole.UserRole) if item else None - has_xml_files = tree_node_obj and self._has_xml_files_recursive(tree_node_obj) + has_xml_files = bool(tree_node_obj and self._has_xml_files_recursive(tree_node_obj)) action_transform = QAction("Alle XML-Dateien transformieren", self) action_transform.setIcon(QIcon(QIcon.fromTheme("system-run"))) @@ -3714,9 +3714,9 @@ class MainWindow(QMainWindow): Returns: bool: True wenn erfolgreich, False bei Fehler """ + pdf_basename = diff_pdf_path.name # Initialisiere am Anfang für Exception-Handler + try: - pdf_basename = diff_pdf_path.name - # Prüfe ob new-PDF existiert if not new_pdf_path.exists(): logger.warning(f"New-PDF nicht gefunden: {pdf_basename}") @@ -3738,7 +3738,11 @@ class MainWindow(QMainWindow): # Diff-Icon beim XML-Knoten entfernen # WICHTIG: xml_item_map verwendet relative Pfade, nicht absolute! - xml_relative_path = xml_file_path.relative_to(self.project.project_dir) + if self.project and self.project.project_dir: + xml_relative_path = xml_file_path.relative_to(self.project.project_dir) + else: + # Fallback: Verwende absoluten Pfad als String + xml_relative_path = xml_file_path map_key = f"{xml_relative_path}|{xsl_id_str}" if map_key in self.xml_item_map: tree_item = self.xml_item_map[map_key]