From 4023aca115db0387c8765fbfd822c46769d27172 Mon Sep 17 00:00:00 2001 From: rc-swag <58423624+rc-swag@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:55:45 +1000 Subject: [PATCH] feat(windows): convert the klog errors to sentry Update all the errors logged using KLog to sentry messages --- .../main/Keyman.System.UpdateStateMachine.pas | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/windows/src/desktop/kmshell/main/Keyman.System.UpdateStateMachine.pas b/windows/src/desktop/kmshell/main/Keyman.System.UpdateStateMachine.pas index b196f755ad1..83959f0377a 100644 --- a/windows/src/desktop/kmshell/main/Keyman.System.UpdateStateMachine.pas +++ b/windows/src/desktop/kmshell/main/Keyman.System.UpdateStateMachine.pas @@ -13,6 +13,7 @@ interface System.IOUtils, System.Types, System.TypInfo, + Sentry.Client, httpuploader, KeymanPaths, @@ -110,6 +111,7 @@ implementation ErrorControlledRegistry, GlobalProxySettings, + Keyman.System.KeymanSentryClient, Keyman.System.DownloadUpdate, Keyman.System.RemoteUpdateCheck, KLog, @@ -234,7 +236,7 @@ destructor TUpdateStateMachine.Destroy; lpState: TUpdateState; begin if (FErrorMessage <> '') and FShowErrors then - KL.Log(FErrorMessage); // TODO: #10210 Log to Sentry + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, '"+FErrorMessage+"'); for lpState := Low(TUpdateState) to High(TUpdateState) do begin @@ -261,8 +263,7 @@ function TUpdateStateMachine.SetRegistryState(Update: TUpdateState): Boolean; if not Registry.OpenKey(SRegKey_KeymanEngine_CU, True) then begin - // TODO: #10210 Log to Sentry - KL.Log('Failed to open registry key: ' + SRegKey_KeymanEngine_CU); + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Failed to open registry key: "'+SRegKey_KeymanEngine_CU+'"'); Exit; end; @@ -273,8 +274,7 @@ function TUpdateStateMachine.SetRegistryState(Update: TUpdateState): Boolean; except on E: ERegistryException do begin - // TODO: #10210 Log to Sentry - KL.Log('Failed to write to registry: ' + E.Message); + TKeymanSentryClient.ReportHandledException(E, 'Failed to write install state machine state'); end; end; @@ -312,8 +312,7 @@ function TUpdateStateMachine.CheckRegistryState: TUpdateState; except on E: ERegistryException do begin - // TODO: #10210 Log to Sentry - KL.Log('Failed to write to registry: ' + E.Message); + TKeymanSentryClient.ReportHandledException(E, 'Failed to read install state machine state'); UpdateState := usIdle; end; end; @@ -341,8 +340,7 @@ function TUpdateStateMachine.GetAutomaticUpdates: Boolean; // I2329 except on E: ERegistryException do begin - // TODO: #10210 Log to Sentry - KL.Log('Failed to read registery: ' + E.Message); + TKeymanSentryClient.ReportHandledException(E, 'Failed to read automatic updates'); Result := False; end; end; @@ -370,8 +368,7 @@ function TUpdateStateMachine.SetApplyNow(Value: Boolean): Boolean; except on E: ERegistryException do begin - // TODO: #10210 Log to Sentry 'Failed to write '+SRegValue_ApplyNow+' to registry: ' + E.Message - KL.Log('Failed to write to registry: ' + E.Message); + TKeymanSentryClient.ReportHandledException(E, 'Failed to write apply now'); end; end; finally @@ -409,8 +406,7 @@ function TUpdateStateMachine.GetState: TStateClass; Result := TStateClass(CurrentState.ClassType) else begin - // TODO: #10210 Log to Sentry - KL.Log('Error CurrentState was uninitiallised: ' ); + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Error CurrentState was uninitiallised'); Result := nil; end; end; @@ -454,9 +450,8 @@ function TUpdateStateMachine.ConvertStateToEnum(const StateClass: TStateClass) : Result := usInstalling else begin - // TODO: #10210 Log to Sentry Result := usIdle; - KL.Log('Unknown StateClass'); // TODO-WINDOWS-UPDATES + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Unknown State Machine class'); end; end; @@ -466,8 +461,7 @@ function TUpdateStateMachine.IsCurrentStateAssigned: Boolean; Result := True else begin - // TODO: #10210 Log to Sentry - KL.Log('Unexpected Error: Current state is not assigned.'); + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Error CurrentState was uninitiallised'); Result := False; end; end; @@ -539,7 +533,8 @@ function TUpdateStateMachine.CurrentStateName: string; procedure TState.HandleFirstRun; begin // If Handle First run hits base implementation - // something is wrong log sentry error + // something is wrong. + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Handle first run called in state:"'+Self.ClassName+'"'); bucStateContext.HandleMSIInstallComplete; end; @@ -638,8 +633,7 @@ procedure UpdateAvailableState.StartDownloadProcess; FResult := TUtilExecute.ShellCurrentUser(0, ParamStr(0), IncludeTrailingPathDelimiter(RootPath), '-bd'); if not FResult then begin - // TODO: #10210 Log to Sentry - KL.Log('TrmfMain: Executing KMshell for download updated Failed'); + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Executing kmshell process to download updated Failed'); ChangeState(IdleState); end; end; @@ -933,10 +927,7 @@ function InstallingState.DoInstallKeyman(SavePath: string): Boolean; if not FResult then begin - // TODO: #10210 Log to Sentry - KL.Log('TUpdateStateMachine.InstallingState.DoInstall: Result = ' + - IntToStr(Ord(FResult))); - // Log message ShowMessage(SysErrorMessage(GetLastError)); + TKeymanSentryClient.Client.MessageEvent(Sentry.Client.SENTRY_LEVEL_ERROR, 'Executing kmshell process to install failed:"'+IntToStr(Ord(FResult))+'"'); end; Result := FResult;