Code-Qualität: Robustere Fehlerbehandlung in MainWindow
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
"""
|
||||
try:
|
||||
pdf_basename = diff_pdf_path.name
|
||||
pdf_basename = diff_pdf_path.name # Initialisiere am Anfang für Exception-Handler
|
||||
|
||||
try:
|
||||
# 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]
|
||||
|
||||
Reference in New Issue
Block a user