From 7d8dff4040cc875913cdd288458f5edfff25106e Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 28 May 2015 11:03:45 -0700 Subject: [PATCH] handle bad requests better (don't fail when connection not available) Don't crash when writing log to protected directory. --- MatterControlApplication.cs | 4 ++-- PrinterControls/TerminalWindow/TerminalWidget.cs | 15 ++++++++++++++- StaticData/Translations/Master.txt | 6 ++++++ Submodules/agg-sharp | 2 +- Utilities/WebUtilities/RequestManager.cs | 10 +++++++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 5f16640ac..d9e6a34d8 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -320,9 +320,9 @@ namespace MatterHackers.MatterControl public enum ReportSeverity2 { Warning, Error } - public void ReportException(Exception e, string key, string value, ReportSeverity2 warningLevel = ReportSeverity2.Warning) + public void ReportException(Exception e, string key = "", string value = "", ReportSeverity2 warningLevel = ReportSeverity2.Warning) { - // do nothing + _raygunClient.Send(e); } private event EventHandler unregisterEvent; diff --git a/PrinterControls/TerminalWindow/TerminalWidget.cs b/PrinterControls/TerminalWindow/TerminalWidget.cs index 71df99109..189808920 100644 --- a/PrinterControls/TerminalWindow/TerminalWidget.cs +++ b/PrinterControls/TerminalWindow/TerminalWidget.cs @@ -214,6 +214,9 @@ namespace MatterHackers.MatterControl base.OnDraw(graphics2D); } + readonly static string writeFaildeWaring = "WARNING: Write Failed!".Localize(); + readonly static string cantAccessPath = "Can't access '{0}'.".Localize(); + private void onExportLogFileSelected(SaveFileDialogParams saveParams) { if (saveParams.FileName != null) @@ -221,7 +224,17 @@ namespace MatterHackers.MatterControl string filePathToSave = saveParams.FileName; if (filePathToSave != null && filePathToSave != "") { - textScrollWidget.WriteToFile(filePathToSave); + try + { + textScrollWidget.WriteToFile(filePathToSave); + } + catch(UnauthorizedAccessException e) + { + PrinterOutputCache.Instance.PrinterLines.Add(""); + PrinterOutputCache.Instance.PrinterLines.Add(writeFaildeWaring); + PrinterOutputCache.Instance.PrinterLines.Add(cantAccessPath.FormatWith(filePathToSave)); + PrinterOutputCache.Instance.PrinterLines.Add(""); + } } } } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 3a86ccfa6..0c455535a 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3274,3 +3274,9 @@ Translated:More English:Share Translated:Share +English:WARNING: Write Failed! +Translated:WARNING: Write Failed! + +English:Can't access '{0}'. +Translated:Can't access '{0}'. + diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 20587cdd3..c70c78502 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 20587cdd3be05b85d1cee98b19d19be3638960ae +Subproject commit c70c78502dd2dcf313f3b3d6dd5d793f0760eec0 diff --git a/Utilities/WebUtilities/RequestManager.cs b/Utilities/WebUtilities/RequestManager.cs index 3129751c0..33f5e45ea 100644 --- a/Utilities/WebUtilities/RequestManager.cs +++ b/Utilities/WebUtilities/RequestManager.cs @@ -153,6 +153,14 @@ namespace MatterHackers.MatterControl { Console.WriteLine("Web exception occurred. Status code: {0}", ex.Status); } + catch (IOException ioException) + { + Console.WriteLine("Web exception occurred. Message: {0}", ioException.Message); + } + catch (Exception e) + { + MatterControlApplication.Instance.ReportException(e); + } } return request; } @@ -161,7 +169,7 @@ namespace MatterHackers.MatterControl { if (request == null) { - throw new ArgumentNullException("request"); + return null; } HttpWebResponse response = null; try