/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> new public static void Handle(Exception ex) { if (ex != null) { // invalid regex - only ArgumentException, without subclasses if (ex.GetType().ToString().Equals("System.ArgumentException") && ex.StackTrace.Contains("System.Text.RegularExpressions")) { MessageBox.Show(ex.Message, "Invalid regular expression", MessageBoxButtons.OK, MessageBoxIcon.Error); } // network access error else if (ex is System.Net.WebException) { MessageBox.Show(ex.Message, "Network access error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // out of memory error else if (ex is System.OutOfMemoryException) { MessageBox.Show(ex.Message, "Out of Memory error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // suggest a bug report for other exceptions { ErrorHandler handler = new ErrorHandler(); handler.txtError.Text = ex.Message; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = <table><tr><td>Exception:<td><code>" + ex.GetType().Name + "</code><tr><td>Message:<td><code>" + ex.Message + "</code><tr><td>Call stack:<td><pre>" + ex.StackTrace + "</pre>"); if (Thread.CurrentThread.Name != "Main thread") { errorMessage.Append("\r\nThread: " + Thread.CurrentThread.Name); } errorMessage.Append("</table>\r\n~~~~\r\n | OS = " + Environment.OSVersion.ToString() + "\r\n | version = " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (!string.IsNullOrEmpty(CurrentArticle)) { string link = "[" + Variables.URLLong + "index.php?title=" + Tools.WikiEncode(CurrentArticle) + "&oldid=" + CurrentRevision.ToString() + "]"; errorMessage.Append("\r\n | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) { errorMessage.Append("\r\n | duplicate = '''ListMaker Text:''' " + ListMakerText); } errorMessage.Append("\r\n}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.textBox1.Text = "AWB encountered " + ex.GetType().Name; handler.ShowDialog(); } } }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> public static void HandleException(Exception ex) { if (ex == null || HandleKnownExceptions(ex)) return; // TODO: suggest a bug report for other exceptions ErrorHandler handler = new ErrorHandler {txtError = {Text = ex.Message}}; var errorMessage = new BugReport(ex).PrintForPhabricator(); handler.txtDetails.Text = errorMessage; handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); Tools.WriteDebug("HandleException", errorMessage); handler.ShowDialog(); }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> public static void HandleException(Exception ex) { if (ex == null || HandleKnownExceptions(ex)) { return; } // TODO: suggest a bug report for other exceptions ErrorHandler handler = new ErrorHandler { txtError = { Text = ex.Message } }; var errorMessage = new BugReport(ex).PrintForPhabricator(); handler.txtDetails.Text = errorMessage; handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); Tools.WriteDebug("HandleException", errorMessage); handler.ShowDialog(); }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> new public static void Handle(Exception ex) { if (ex == null) return; // invalid regex - only ArgumentException, without subclasses if (ex is ArgumentException && ex.StackTrace.Contains("System.Text.RegularExpressions")) { MessageBox.Show(ex.Message, "Invalid regular expression", MessageBoxButtons.OK, MessageBoxIcon.Error); } // network access error else if (ex is System.Net.WebException || ex.InnerException is System.Net.WebException) { MessageBox.Show(ex.Message, "Network access error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // out of memory error else if (ex is OutOfMemoryException) { MessageBox.Show(ex.Message, "Out of Memory error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // disk writer error / full else if (ex is System.IO.IOException) { MessageBox.Show(ex.Message, "Disk write error - is disk full?", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // suggest a bug report for other exceptions { ErrorHandler handler = new ErrorHandler {txtError = {Text = ex.Message}}; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = "); if (Thread.CurrentThread.Name != "Main thread") errorMessage.Append("\r\nThread: " + Thread.CurrentThread.Name); errorMessage.Append("<table>"); FormatException(ex, errorMessage, ExceptionKind.TopLevel); errorMessage.Append("</table>\r\n~~~~\r\n | OS = " + Environment.OSVersion + "\r\n | version = " + Assembly.GetExecutingAssembly().GetName().Version); // suppress unhandled exception if Variables constructor says 'ouch' string revision; try { revision = Variables.Revision; } catch { revision = "?"; } if (!revision.Contains("?")) errorMessage.Append(", revision " + revision); if (!string.IsNullOrEmpty(CurrentPage)) { // don't use Tools.WikiEncode here, to keep code portable to updater // as it's not a pretty URL, we don't need to follow the MediaWiki encoding rules string link = "[" + Variables.URLIndex + "?title=" + HttpUtility.UrlEncode(CurrentPage) + "&oldid=" + CurrentRevision + "]"; errorMessage.Append("\r\n | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) errorMessage.Append("\r\n | duplicate = '''ListMaker Text:''' " + ListMakerText); if (!string.IsNullOrEmpty(Variables.URL)) errorMessage.Append("\r\n | site = " + Variables.URL); errorMessage.Append("\r\n}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); handler.ShowDialog(); } }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> new public static void Handle(Exception ex) { if (ex == null || HandleKnownExceptions(ex)) { return; } // suggest a bug report for other exceptions ErrorHandler handler = new ErrorHandler { txtError = { Text = ex.Message } }; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = "); var thread = ex is ApiException ? (ex as ApiException).ThrowingThread : Thread.CurrentThread; if (thread.Name != "Main thread") { errorMessage.AppendLine("nThread: " + thread.Name); } errorMessage.Append("<table>"); FormatException(ex, errorMessage, ExceptionKind.TopLevel); errorMessage.AppendLine("</table>"); if (AppendToEventHandler != null) { foreach (Delegate d in AppendToEventHandler.GetInvocationList()) { string retval = d.DynamicInvoke().ToString(); if (!string.IsNullOrEmpty(retval)) { errorMessage.AppendLine(retval); } } } errorMessage.AppendLine("~~~~"); errorMessage.AppendLine(" | OS = " + Environment.OSVersion); AssemblyName hostingApp = Assembly.GetExecutingAssembly().GetName(); errorMessage.Append(string.Format(" | version = {0} ({1}), {2} ({3})", Application.ProductName, Application.ProductVersion, hostingApp.Name, hostingApp.Version)); // suppress unhandled exception if Variables constructor says 'ouch' string revision; try { revision = Variables.Revision; } catch { revision = "?"; } if (!revision.Contains("?")) { errorMessage.AppendLine(", revision " + revision); } errorMessage.AppendLine(" | net = " + Environment.Version); if (!string.IsNullOrEmpty(CurrentPage)) { // don't use Tools.WikiEncode here, to keep code portable to updater // as it's not a pretty URL, we don't need to follow the MediaWiki encoding rules string link = "[" + Variables.URLIndex + "?title=" + HttpUtility.UrlEncode(CurrentPage) + "&oldid=" + CurrentRevision + "]"; errorMessage.AppendLine(" | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) { errorMessage.AppendLine(" | duplicate = '''ListMaker Text:''' " + ListMakerText); } if (!string.IsNullOrEmpty(Variables.URL)) { errorMessage.AppendLine(" | site = " + Variables.URL); } errorMessage.AppendLine(" | workaround = <!-- Any workaround for the problem -->"); errorMessage.AppendLine(" | fix_version = <!-- Version of AWB the fix will be included in; AWB developer will complete when it's fixed -->"); errorMessage.AppendLine("}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); handler.ShowDialog(); }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> new public static void Handle(Exception ex) { if (ex != null) { // invalid regex - only ArgumentException, without subclasses if (ex.GetType().ToString().Equals("System.ArgumentException") && ex.StackTrace.Contains("System.Text.RegularExpressions")) { MessageBox.Show(ex.Message, "Invalid regular expression", MessageBoxButtons.OK, MessageBoxIcon.Error); } // network access error else if (ex is System.Net.WebException) { MessageBox.Show(ex.Message, "Network access error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // out of memory error else if (ex is System.OutOfMemoryException) { MessageBox.Show(ex.Message, "Out of Memory error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // suggest a bug report for other exceptions { ErrorHandler handler = new ErrorHandler(); handler.txtError.Text = ex.Message; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = <table><tr><td>Exception:<td><code>" + ex.GetType().Name + "</code><tr><td>Message:<td><code>" + ex.Message + "</code><tr><td>Call stack:<td><pre>" + ex.StackTrace + "</pre>"); if (Thread.CurrentThread.Name != "Main thread") errorMessage.Append("\r\nThread: " + Thread.CurrentThread.Name); errorMessage.Append("</table>\r\n~~~~\r\n | OS = " + Environment.OSVersion.ToString() + "\r\n | version = " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); if (!string.IsNullOrEmpty(CurrentArticle)) { string link = "[" + Variables.URLLong + "index.php?title=" + Tools.WikiEncode(CurrentArticle) + "&oldid=" + CurrentRevision.ToString() + "]"; errorMessage.Append("\r\n | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) errorMessage.Append("\r\n | duplicate = '''ListMaker Text:''' " + ListMakerText); errorMessage.Append("\r\n}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.textBox1.Text = "AWB encountered " + ex.GetType().Name; handler.ShowDialog(); } } }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> new public static void Handle(Exception ex) { if (ex != null) { // invalid regex - only ArgumentException, without subclasses if (ex is ArgumentException && ex.StackTrace.Contains("System.Text.RegularExpressions")) { MessageBox.Show(ex.Message, "Invalid regular expression", MessageBoxButtons.OK, MessageBoxIcon.Error); } // network access error else if (ex is System.Net.WebException || ex.InnerException is System.Net.WebException) { MessageBox.Show(ex.Message, "Network access error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // out of memory error else if (ex is OutOfMemoryException) { MessageBox.Show(ex.Message, "Out of Memory error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // disk writer error / full else if (ex is System.IO.IOException) { MessageBox.Show(ex.Message, "Disk write error - is disk full?", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // suggest a bug report for other exceptions { ErrorHandler handler = new ErrorHandler(); handler.txtError.Text = ex.Message; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = "); if (Thread.CurrentThread.Name != "Main thread") { errorMessage.Append("\r\nThread: " + Thread.CurrentThread.Name); } errorMessage.Append("<table>"); FormatException(ex, errorMessage, ExceptionKind.TopLevel); errorMessage.Append("</table>\r\n~~~~\r\n | OS = " + Environment.OSVersion + "\r\n | version = " + Assembly.GetExecutingAssembly().GetName().Version); // suppress unhandled exception if Variables constructor says 'ouch' string revision; try { revision = Variables.Revision; } catch { revision = "?"; } if (!revision.Contains("?")) { errorMessage.Append(", revision " + revision); } if (!string.IsNullOrEmpty(CurrentPage)) { // don't use Tools.WikiEncode here, to keep code portable to updater // as it's not a pretty URL, we don't need to follow the MediaWiki encoding rules string link = "[" + Variables.URLIndex + "?title=" + HttpUtility.UrlEncode(CurrentPage) + "&oldid=" + CurrentRevision + "]"; errorMessage.Append("\r\n | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) { errorMessage.Append("\r\n | duplicate = '''ListMaker Text:''' " + ListMakerText); } if (!string.IsNullOrEmpty(Variables.URL)) { errorMessage.Append("\r\n | site = " + Variables.URL); } errorMessage.Append("\r\n}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); handler.ShowDialog(); } } }
/// <summary> /// Displays exception information. Should be called from try...catch handlers /// </summary> /// <param name="ex">Exception object to handle</param> public static void HandleException(Exception ex) { if (ex == null || HandleKnownExceptions(ex)) return; // TODO: suggest a bug report for other exceptions ErrorHandler handler = new ErrorHandler { txtError = { Text = ex.Message } }; StringBuilder errorMessage = new StringBuilder("{{AWB bug\r\n | status = new <!-- when fixed replace with \"fixed\" -->\r\n | description = "); var thread = ex is ApiException ? (ex as ApiException).ThrowingThread : Thread.CurrentThread; if (thread.Name != "Main thread") errorMessage.AppendLine("nThread: " + thread.Name); errorMessage.Append("<table>"); FormatException(ex, errorMessage, ExceptionKind.TopLevel); errorMessage.AppendLine("</table>"); var exception = ex as ApiException; if (exception != null) { string extra = exception.GetExtraSpecificInformation(); if(!string.IsNullOrEmpty(extra)) { errorMessage.AppendLine(extra); } } errorMessage.AppendLine(ex.ToString()); if (AppendToEventHandler != null) { foreach (Delegate d in AppendToEventHandler.GetInvocationList()) { string retval = d.DynamicInvoke().ToString(); if (!string.IsNullOrEmpty(retval)) errorMessage.AppendLine(retval); } } errorMessage.AppendLine("~~~~"); errorMessage.AppendLine(" | OS = " + Environment.OSVersion); AssemblyName hostingApp = Assembly.GetExecutingAssembly().GetName(); errorMessage.Append(string.Format(" | version = {0} ({1}), {2} ({3})", Application.ProductName, Application.ProductVersion, hostingApp.Name, hostingApp.Version)); // suppress unhandled exception if Variables constructor says 'ouch' string revision; try { revision = Variables.Revision; } catch { revision = "?"; } if (!revision.Contains("?")) errorMessage.AppendLine(", revision " + revision); errorMessage.AppendLine(" | net = " + Environment.Version); if (!string.IsNullOrEmpty(CurrentPage)) { // don't use Tools.WikiEncode here, to keep code portable to updater // as it's not a pretty URL, we don't need to follow the MediaWiki encoding rules string link = "[" + Variables.URLIndex + "?title=" + HttpUtility.UrlEncode(CurrentPage) + "&oldid=" + CurrentRevision + "]"; errorMessage.AppendLine(" | duplicate = [encountered while processing page ''" + link + "'']"); } else if (!string.IsNullOrEmpty(ListMakerText)) errorMessage.AppendLine(" | duplicate = '''ListMaker Text:''' " + ListMakerText); if (!string.IsNullOrEmpty(Variables.URL)) errorMessage.AppendLine(" | site = " + Variables.URL); errorMessage.AppendLine(" | workaround = <!-- Any workaround for the problem -->"); errorMessage.AppendLine(" | fix_version = <!-- Version of AWB the fix will be included in; AWB developer will complete when it's fixed -->"); errorMessage.AppendLine("}}"); handler.txtDetails.Text = errorMessage.ToString(); handler.txtSubject.Text = ex.GetType().Name + " in " + Thrower(ex); Tools.WriteDebug("HandleException", errorMessage.ToString()); handler.ShowDialog(); }