~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/error.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

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