Skip to content

Commit

Permalink
feat(windows): convert the klog errors to sentry
Browse files Browse the repository at this point in the history
Update all the errors logged using KLog to sentry messages
  • Loading branch information
rc-swag committed Nov 28, 2024
1 parent caef322 commit 4023aca
Showing 1 changed file with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface
System.IOUtils,
System.Types,
System.TypInfo,
Sentry.Client,

httpuploader,
KeymanPaths,
Expand Down Expand Up @@ -110,6 +111,7 @@ implementation
ErrorControlledRegistry,

GlobalProxySettings,
Keyman.System.KeymanSentryClient,
Keyman.System.DownloadUpdate,
Keyman.System.RemoteUpdateCheck,
KLog,
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4023aca

Please sign in to comment.