Example #1
0
        public static void SetLocation(ProductException ex, Mono.Cecil.MethodDefinition method)
        {
            if (!method.HasBody)
            {
                return;
            }

#if MTOUCH
            Driver.App.LoadSymbols();
#endif

            if (method.Body.Instructions.Count == 0)
            {
                return;
            }

            var seq = method.Body.Instructions [0].SequencePoint;

            if (seq == null)
            {
                return;
            }

            ex.FileName   = seq.Document.Url;
            ex.LineNumber = seq.StartLine;
        }
Example #2
0
        public static ProductException CreateError(int code, Exception innerException, Mono.Cecil.TypeReference location, string message, params object[] args)
        {
            var e = new ProductException(code, true, innerException, message, args);

            if (location != null)
            {
                var td = location.Resolve();

                if (td.HasMethods)
                {
                    foreach (var method in td.Methods)
                    {
                        if (!method.IsConstructor)
                        {
                            continue;
                        }
                        SetLocation(e, method);
                        if (e.FileName != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(e);
        }
Example #3
0
        public static ProductException CreateError(int code, Exception innerException, Mono.Cecil.MethodDefinition location, string message, params object[] args)
        {
            var e = new ProductException(code, true, innerException, message, args);

            if (location != null)
            {
                SetLocation(e, location);
            }
            return(e);
        }
Example #4
0
        public static ProductException Create(Application app, int code, bool error, Exception innerException, Mono.Cecil.MethodDefinition location, Instruction instruction, string message, params object [] args)
        {
            var e = new ProductException(code, error, innerException, message, args);

            if (location != null)
            {
                SetLocation(app, e, location, instruction);
            }
            return(e);
        }
Example #5
0
        static bool ShowInternal(Exception e)
        {
            ProductException mte   = (e as ProductException);
            bool             error = true;

            if (mte != null)
            {
                error = mte.Error;

                if (!error && GetWarningLevel(mte.Code) == WarningLevel.Disable)
                {
                    return(false);                    // This is an ignored warning.
                }
                Console.Error.WriteLine(mte.ToString());

                // Errors with code >= 9000 are activation/licensing errors.
                // PROTIP: do not show a stack trace that points the exact method where the license checks are done
                if (mte.Code > 8999)
                {
                    return(error);
                }

                if (Verbosity > 1)
                {
                    ShowInner(e);
                }

                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
#if MTOUCH || MMP
            }
            else if (IsExpectedException == null || !IsExpectedException(e))
            {
                Console.Error.WriteLine("error " + Prefix + "0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com");
                Console.Error.WriteLine(e.ToString());
#endif
            }
            else
            {
                Console.Error.WriteLine(e.ToString());
                if (Verbosity > 1)
                {
                    ShowInner(e);
                }
                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            }

            return(error);
        }
Example #6
0
        public static void SetLocation(Application app, ProductException ex, Mono.Cecil.MethodDefinition method, Instruction instruction = null)
        {
            if (!method.HasBody)
            {
                return;
            }

            if (instruction == null && method.Body.Instructions.Count == 0)
            {
                return;
            }

            if (instruction == null)
            {
                instruction = method.Body.Instructions [0];
            }
#if MTOUCH
            app.LoadSymbols();
#endif

            if (!method.DebugInformation.HasSequencePoints)
            {
                return;
            }

            // Find the sequence point with the highest offset that is less than or equal to the instruction's offset
            SequencePoint seq = null;
            foreach (var pnt in method.DebugInformation.SequencePoints)
            {
                if (pnt.Offset > instruction.Offset)
                {
                    continue;
                }

                if (seq != null && seq.Offset >= pnt.Offset)
                {
                    continue;
                }

                seq = pnt;
            }
            if (seq == null)
            {
                return;
            }

            ex.FileName   = seq.Document.Url;
            ex.LineNumber = seq.StartLine;
        }
        static bool ShowInternal(Exception e)
        {
            ProductException mte   = (e as ProductException);
            bool             error = true;

            if (mte != null)
            {
                error = mte.Error;

                if (!error && GetWarningLevel(mte.Code) == WarningLevel.Disable)
                {
                    return(false);                    // This is an ignored warning.
                }
                Console.Error.WriteLine(mte.ToString());

                if (Verbosity > 1)
                {
                    ShowInner(e);
                }

                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
#if MTOUCH || MMP
            }
            else if (IsExpectedException == null || !IsExpectedException(e))
            {
                Console.Error.WriteLine("error " + Prefix + "0000: Unexpected error - Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new");
                Console.Error.WriteLine(e.ToString());
#endif
            }
            else
            {
                Console.Error.WriteLine(e.ToString());
                if (Verbosity > 1)
                {
                    ShowInner(e);
                }
                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            }

            return(error);
        }
Example #8
0
		public static void SetLocation (ProductException ex, Mono.Cecil.MethodDefinition method)
		{
			if (!method.HasBody)
				return;

#if MTOUCH
			Driver.App.LoadSymbols ();
#endif

			if (method.Body.Instructions.Count == 0)
				return;

			var seq = method.Body.Instructions [0].SequencePoint;

			if (seq == null)
				return;

			ex.FileName = seq.Document.Url;
			ex.LineNumber = seq.StartLine;
		}
Example #9
0
		public static ProductException CreateError (int code, Exception innerException, Mono.Cecil.TypeReference location, string message, params object[] args)
		{
			var e = new ProductException (code, true, innerException, message, args);
			if (location != null) {
				var td = location.Resolve ();

				if (td.HasMethods) {
					foreach (var method in td.Methods) {
						if (!method.IsConstructor)
							continue;
						SetLocation (e, method);
						if (e.FileName != null)
							break;
					}
				}
			}
			return e;
		}
Example #10
0
		public static ProductException CreateError (int code, Exception innerException, Mono.Cecil.MethodDefinition location, string message, params object[] args)
		{
			var e = new ProductException (code, true, innerException, message, args);
			if (location != null)
				SetLocation (e, location);
			return e;
		}