PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/error.cs

https://github.com/kjpou1/maccore
C# | 150 lines | 79 code | 22 blank | 49 comment | 13 complexity | ae95a21ff4afd5bb3768d7ceec53f2d2 MD5 | raw file
Possible License(s): Apache-2.0
  1. //
  2. // error.cs: Error handling code for bmac/btouch
  3. //
  4. // Authors:
  5. // Rolf Bjarne Kvinge <rolf@xamarin.com
  6. // Sebastien Pouliot <sebastien@xamarin.com>
  7. //
  8. // Copyright 2012 Xamarin, Inc.
  9. //
  10. //
  11. using System;
  12. using System.Collections.Generic;
  13. // Error allocation
  14. //
  15. // BI0xxx the generator itself, e.g. parameters, environment
  16. // BI1xxx code generation
  17. // BI10xx errors
  18. // BI1001 Do not know how to make a trampoline for {0}
  19. // BI1002 Unknown kind {0} in method '{1}'
  20. // BI1003 The delegate method {0}.{1} needs to take at least one parameter
  21. // BI1004 The delegate method {0}.{1} is missing the [EventArgs] attribute (has {2} parameters)
  22. // BI1005 EventArgs in {0}.{1} attribute should not include the text `EventArgs' at the end
  23. // BI1006 The delegate method {0}.{1} is missing the [DelegateName] attribute (or EventArgs)
  24. // BI1007 Unknown attribute {0} on {1}
  25. // BI1008 [IsThreadStatic] is only valid on properties that are also [Static]
  26. // BI1009 No selector specified for method `{0}.{1}'
  27. // BI1010 No Export attribute on {0}.{1} property
  28. // BI1011 Do not know how to extract type {0}/{1} from an NSDictionary
  29. // BI1012 No Export or Bind attribute defined on {0}.{1}
  30. // BI1013 Unsupported type for Fields (string), you probably meant NSString
  31. // BI1014 Unsupported type for Fields: {0}
  32. // BI1015 In class {0} You specified the Events property, but did not bind those to names with Delegates
  33. // BI1016 The delegate method {0}.{1} is missing the [DefaultValue] attribute
  34. // BI1017 Do not know how to make a signature for {0}
  35. // BI1018 No [Export] attribute on property {0}.{1}
  36. // BI1019 Invalid [NoDefaultValue] attribute on method `{0}.{1}'
  37. // BI1020 Unsupported type {0} used on exported method {1}.{2}
  38. // BI1021 Unsupported type for read/write Fields: {0}
  39. // BI1022 Model classes can not be categories
  40. // BI11xx warnings
  41. // BI1101 Trying to use a string as a [Target]
  42. // BI1102 Using the deprecated EventArgs for a delegate signature in {0}.{1}, please use DelegateName instead
  43. // BI2xxx reserved
  44. // BI3xxx reserved
  45. // BI4xxx reserved
  46. // BI5xxx reserved
  47. // BI6xxx reserved
  48. // BI7xxx reserved
  49. // BI8xxx reserved
  50. // BI9xxx reserved
  51. public class BindingException : Exception {
  52. public BindingException (int code, string message, params object[] args) :
  53. this (code, false, message, args)
  54. {
  55. }
  56. public BindingException (int code, bool error, string message, params object[] args) :
  57. this (code, error, null, message, args)
  58. {
  59. }
  60. public BindingException (int code, bool error, Exception innerException, string message, params object[] args) :
  61. base (String.Format (message, args), innerException)
  62. {
  63. Code = code;
  64. Error = error;
  65. }
  66. public int Code { get; private set; }
  67. public bool Error { get; private set; }
  68. // http://blogs.msdn.com/b/msbuild/archive/2006/11/03/msbuild-visual-studio-aware-error-messages-and-message-formats.aspx
  69. public override string ToString ()
  70. {
  71. return String.Format ("{0} BI{1:0000}: {3}: {2}",
  72. Error ? "error" : "warning", Code, Message, BindingTouch.ToolName);
  73. }
  74. }
  75. public static class ErrorHelper {
  76. static public int Verbosity { get; set; }
  77. static public void Show (Exception e)
  78. {
  79. List<Exception> exceptions = new List<Exception> ();
  80. bool error = false;
  81. CollectExceptions (e, exceptions);
  82. foreach (var ex in exceptions)
  83. error |= ShowInternal (ex);
  84. if (error)
  85. Environment.Exit (1);
  86. }
  87. static void CollectExceptions (Exception ex, List<Exception> exceptions)
  88. {
  89. #if NET_4_0
  90. AggregateException ae = ex as AggregateException;
  91. if (ae != null) {
  92. foreach (var ie in ae.InnerExceptions)
  93. CollectExceptions (ie, exceptions);
  94. } else {
  95. exceptions.Add (ex);
  96. }
  97. #else
  98. exceptions.Add (ex);
  99. #endif
  100. }
  101. static bool ShowInternal (Exception e)
  102. {
  103. BindingException mte = (e as BindingException);
  104. bool error = true;
  105. if (mte != null) {
  106. error = mte.Error;
  107. Console.Out.WriteLine (mte.ToString ());
  108. if (Verbosity > 1) {
  109. Exception ie = e.InnerException;
  110. if (ie != null) {
  111. if (Verbosity > 3) {
  112. Console.Error.WriteLine ("--- inner exception");
  113. Console.Error.WriteLine (ie);
  114. Console.Error.WriteLine ("---");
  115. } else {
  116. Console.Error.WriteLine ("\t{0}", ie.Message);
  117. }
  118. }
  119. }
  120. if (Verbosity > 2)
  121. Console.Error.WriteLine (e.StackTrace);
  122. } else {
  123. Console.Out.WriteLine ("error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com");
  124. Console.Out.WriteLine (e.ToString ());
  125. }
  126. return error;
  127. }
  128. }