From e9a78cf6a4882704a883985a80cb5922ce22b260 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Mon, 27 Apr 2026 11:30:37 +0200 Subject: [PATCH] Improve error handling and logging for rights and indexing Enhanced error handling in ClassWD_Rechte to unlock objects after exceptions and prevent resource locks. Refactored frmNIHauptseite to add detailed debug logging and robust error handling in File_SetBooleanIndex, including better handling of missing or invalid index values. Replaced SetErrorMeldung with File_SetBooleanIndex for AD post-processing errors. These changes improve traceability and reliability. --- ToolCollection/ClassWD_Rechte.vb | 9 ++++++++- ToolCollection/frmNIHauptseite.vb | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ToolCollection/ClassWD_Rechte.vb b/ToolCollection/ClassWD_Rechte.vb index e1b9c4c..b69907b 100644 --- a/ToolCollection/ClassWD_Rechte.vb +++ b/ToolCollection/ClassWD_Rechte.vb @@ -393,13 +393,13 @@ Public Class ClassWD_Rechte End Function Private Function WorkRight(_methode As String, createdFolder As String, _form As Boolean, oWMObject As WINDREAMLib.WMObject, deleteRights As Boolean, folgeRegel As Boolean, _UserOrGroup As String, _GruppenUserRecht As String, _lRight As Integer) As Boolean + Dim Object2Change As WINDREAMLib.WMObject = Nothing Try Dim _Erfolgreich As Boolean = True Dim UserGroupRelation Dim UserOrGroup Dim oGroup Dim oUSer - Dim Object2Change As WINDREAMLib.WMObject If _methode = "AddRightFolder" Then Object2Change = oWMObject.aParentWMObject ElseIf _methode = "AddRightCreatedFolder" Then @@ -731,6 +731,13 @@ Public Class ClassWD_Rechte Return _Erfolgreich Catch ex As Exception _Logger.Error(ex) + Try + If Object2Change IsNot Nothing AndAlso Object2Change.aLocked Then + Object2Change.unlock() + _Logger.Debug("WorkRight Catch: Object2Change unlocked after error.") + End If + Catch + End Try Return False End Try End Function diff --git a/ToolCollection/frmNIHauptseite.vb b/ToolCollection/frmNIHauptseite.vb index 5cfa47b..bd925d5 100644 --- a/ToolCollection/frmNIHauptseite.vb +++ b/ToolCollection/frmNIHauptseite.vb @@ -1913,7 +1913,7 @@ Public Class frmNIHauptseite If adReworkOk = False Then _Logger.Warn($"## Nachbearbeitung AD für [{pMyWMDoc.aName}] fehlgeschlagen - Error-Index wird gesetzt") File_SetBooleanIndex(True, pMyWMDoc, aktivesProfil.IndexValidation) - SetErrorMeldung("Rechtevergabe fehlgeschlagen", pMyWMDoc, aktivesProfil.IndexFehler) + File_SetBooleanIndex(True, pMyWMDoc, aktivesProfil.IndexFehler) End If Else If aktivesProfil.NachbearbeitungAD = True Then @@ -2547,12 +2547,22 @@ Public Class frmNIHauptseite 'Ab Hier Error prüfen Sub File_SetBooleanIndex(ByVal _value As Boolean, ByVal _dok As WINDREAMLib.WMObject, ByVal _Indexname As String) Try + _Logger.Debug($"File_SetBooleanIndex called: Index=[{_Indexname}] Value=[{_value}] Doc=[{If(_dok IsNot Nothing, _dok.aName, "NULL")}]") If _Indexname <> "" Then 'Überprüfen ob Boolean-Value bereits gesetzt wurde? - Dim akt_Status As Boolean = CBool(_dok.GetVariableValue(_Indexname)) + Dim akt_Status As Boolean = False + Try + Dim rawValue As Object = _dok.GetVariableValue(_Indexname) + _Logger.Debug($"File_SetBooleanIndex: rawValue=[{If(rawValue IsNot Nothing, rawValue.ToString, "NULL")}]") + If rawValue IsNot Nothing Then + akt_Status = CBool(rawValue) + End If + Catch ex As Exception + _Logger.Debug($"File_SetBooleanIndex: GetVariableValue threw exception - treating as False. Error: {ex.Message}") + akt_Status = False + End Try If akt_Status <> _value Then - 'Index muß angepasst werden - _Logger.Debug("Validation Index not set to '" & _value.ToString & "'.") + _Logger.Debug($"File_SetBooleanIndex: writing [{_value}] to index [{_Indexname}]") Dim arrIndex() As String = Nothing Dim arrValue() As String = Nothing 'Nun die Datei indexieren @@ -2577,6 +2587,8 @@ Public Class frmNIHauptseite 'Validation muß nicht angepasst werden _Logger.Debug("Validation Index already set to '" & _value & "'.") End If + Else + _Logger.Warn($"File_SetBooleanIndex: _Indexname is empty - no index written! (Doc=[{If(_dok IsNot Nothing, _dok.aName, "NULL")}] Value=[{_value}])") End If Catch ex As Exception _Logger.Warn("Error in File_SetBooleanIndex")