[PreviewHandlers]Ignore telemetry exceptions (#28612)

This commit is contained in:
Jaime Bernardo 2023-09-19 15:41:17 +01:00 committed by GitHub
parent b471c98f7e
commit e09839dd6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 9 deletions

View File

@ -78,7 +78,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
Resize += FormResized;
base.DoPreview(fs);
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
try
{
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
}
catch (Exception ex)
{
@ -148,7 +154,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
/// <param name="dataSource">Stream reference to access source file.</param>
private void PreviewError<T>(Exception exception, T dataSource)
{
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewError { Message = exception.Message });
try
{
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewError { Message = exception.Message });
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
Controls.Clear();
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GcodeNotPreviewedError);

View File

@ -200,11 +200,23 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
}
});
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed());
try
{
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed());
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
}
catch (Exception ex)
{
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = ex.Message });
try
{
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = ex.Message });
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
Controls.Clear();
_infoBarDisplayed = true;

View File

@ -161,11 +161,23 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
}
}
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewed());
try
{
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewed());
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
}
catch (Exception ex)
{
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewError { Message = ex.Message });
try
{
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewError { Message = ex.Message });
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
Controls.Clear();
_infoBar = GetTextBoxControl(Resources.PdfNotPreviewedError);

View File

@ -143,7 +143,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
}
catch (Exception ex)
{
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = ex.Message });
try
{
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = ex.Message });
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
}
try
@ -160,7 +166,13 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
AddWebViewControl(svgData);
Resize += FormResized;
base.DoPreview(dataSource);
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewed());
try
{
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewed());
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
}
catch (Exception ex)
{
@ -288,7 +300,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
/// <param name="dataSource">Stream reference to access source file.</param>
private void PreviewError<T>(Exception exception, T dataSource)
{
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = exception.Message });
try
{
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = exception.Message });
}
catch
{ // Should not crash if sending telemetry is failing. Ignore the exception.
}
Controls.Clear();
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.SvgNotPreviewedError);