diff --git a/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs b/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs index d70261118b..7ddec18b64 100644 --- a/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs +++ b/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs @@ -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 /// Stream reference to access source file. private void PreviewError(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); diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs index 4364792cf5..06c5c4af3c 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs @@ -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; diff --git a/src/modules/previewpane/PdfPreviewHandler/PdfPreviewHandlerControl.cs b/src/modules/previewpane/PdfPreviewHandler/PdfPreviewHandlerControl.cs index ed1e94ee19..26bec7c0fa 100644 --- a/src/modules/previewpane/PdfPreviewHandler/PdfPreviewHandlerControl.cs +++ b/src/modules/previewpane/PdfPreviewHandler/PdfPreviewHandlerControl.cs @@ -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); diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs index 1b89137654..ca8a169413 100644 --- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs +++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs @@ -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 /// Stream reference to access source file. private void PreviewError(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);