Beispiel #1
0
        private void Write(SentryStacktrace trace)
        {
            if (trace == null || trace.Frames.Count == 0)
            {
                return;
            }

            writer.WritePropertyName("sentry.interfaces.Stacktrace");
            writer.WriteStartObject();
            {
                writer.WritePropertyName("frames");
                writer.WriteStartArray();
                for (int i = 0; i < trace.Frames.Count; i++)
                {
                    var frame = trace.Frames[i];
                    writer.WriteStartObject();
                    {
                        Write("filename", frame.Filename);
                        Write("function", frame.Function);
                        Write("lineno", frame.LineNumber.ToString());
                    }
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }
            writer.WriteEndObject();
        }
Beispiel #2
0
        private static SentryStacktrace ParseUnityStackTrace(string unityTrace)
        {
            /*
             * Example Unity Trace String:
             *
             * ExceptionGenerator.ThrowNestedB () (at Assets/Script/ExceptionGenerator.cs:26)
             * ExceptionGenerator.ThrowNestedA () (at Assets/Script/ExceptionGenerator.cs:22)
             * ExceptionGenerator.Update () (at Assets/Script/ExceptionGenerator.cs:13)
             * RamjetAnvil.StateMachine.StateMachine`1[StartupScreen].Transition (StateId stateId, System.Object[] args)
             */

            var t     = new SentryStacktrace();
            var lines = unityTrace.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = lines.Length - 1; i >= 0; i--)
            {
                var parts = lines[i].Split(new[] { " (at ", ".cs:" }, StringSplitOptions.RemoveEmptyEntries);
                var frame = new ExceptionFrame();
                if (parts.Length == 3)
                {
                    frame.Function   = parts[0];
                    frame.Filename   = parts[1] + ".cs";
                    frame.LineNumber = Int32.Parse(parts[2].Replace(")", ""));
                    t.Frames.Add(frame);
                }
                else
                {
                    frame.Function   = lines[i];
                    frame.Filename   = "unknown";
                    frame.LineNumber = -1;
                }
            }

            return(t);
        }
Beispiel #3
0
        private static SentryStacktrace ParseExceptionStackTrace(Exception exception)
        {
            var t = new SentryStacktrace();

            StackTrace trace = new StackTrace(exception, true);

            for (int i = 0; i < trace.FrameCount; i++)
            {
                var frame = trace.GetFrame(i);

                int lineNo = frame.GetFileLineNumber();

                if (lineNo == 0)
                {
                    //The pdb files aren't currently available
                    lineNo = frame.GetILOffset();
                }

                var method    = frame.GetMethod();
                var frameData = new ExceptionFrame()
                {
                    Filename = frame.GetFileName(),
                    //Module = (method.DeclaringType != null) ? method.DeclaringType.FullName : null,
                    Function = method.Name,
                    //Source = method.ToString(),
                    LineNumber = lineNo,
                };

                t.Frames.Add(frameData);
            }

            return(t);
        }
Beispiel #4
0
        private static SentryStacktrace ParseUnityStackTrace(string unityTrace)
        {
            /*
             * Example Unity Trace String:
             *
             * ExceptionGenerator.ThrowNestedB () (at Assets/Script/ExceptionGenerator.cs:26)
             * ExceptionGenerator.ThrowNestedA () (at Assets/Script/ExceptionGenerator.cs:22)
             * ExceptionGenerator.Update () (at Assets/Script/ExceptionGenerator.cs:13)
             */

            var t = new SentryStacktrace();

            var lines = unityTrace.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < lines.Length; i++)
            {
                var parts = lines[i].Split(new[] { "(", ")", ":" }, StringSplitOptions.RemoveEmptyEntries);
                var frame = new ExceptionFrame();
                frame.Function   = parts[0];
                frame.Filename   = parts[2].Remove(0, 3);
                frame.LineNumber = Int32.Parse(parts[3]);
                t.Frames.Add(frame);
            }

            return(t);
        }
Beispiel #5
0
        public JsonPacket(UnityLogEvent log)
        {
            EventID   = GenerateGuid();
            TimeStamp = DateTime.UtcNow;
            Logger    = "root";
            Project   = "default";
            Platform  = "csharp";

            Message = log.Message;
            Level   = ErrorLevel.error;

            Exception         = new SentryException();
            Exception.Type    = log.LogType.ToString();
            Exception.Message = log.Message;
            StackTrace        = ParseUnityStackTrace(log.StackTrace);

            // Get assemblies.

            /*Modules = new List<Module>();
             * foreach (System.Reflection.Module m in Utilities.SystemUtil.GetModules()) {
             *  Modules.Add(new Module() {
             *      Name = m.ScopeName,
             *      Version = m.ModuleVersionId.ToString()
             *  });
             * }*/
        }
Beispiel #6
0
        public JsonPacket(string project, Exception e)
        {
            Initialize();
            Message = e.Message;

            if (e.TargetSite != null)
            {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse => not for dynamic types.
                Culprit = String.Format("{0} in {1}", ((e.TargetSite.ReflectedType == null) ? "<dynamic type>" : e.TargetSite.ReflectedType.FullName), e.TargetSite.Name);
            // ReSharper restore ConditionIsAlwaysTrueOrFalse
            }

            Project = project;
            ServerName = System.Environment.MachineName;
            Level = ErrorLevel.error;

            Exception = new SentryException(e);
            Exception.Module = e.Source;
            Exception.Type = e.GetType().Name;
            Exception.Value = e.Message;

            StackTrace = new SentryStacktrace(e);
            if (StackTrace.Frames.Count == 0) {
                StackTrace = null;
            }
        }
Beispiel #7
0
        public JsonPacket(string project, Exception e)
        {
            Initialize();
            Message = e.Message;

            if (e.TargetSite != null)
            {
// ReSharper disable ConditionIsAlwaysTrueOrFalse => not for dynamic types.
                Culprit = String.Format("{0} in {1}", ((e.TargetSite.ReflectedType == null) ? "<dynamic type>" : e.TargetSite.ReflectedType.FullName), e.TargetSite.Name);
// ReSharper restore ConditionIsAlwaysTrueOrFalse
            }

            Project    = project;
            ServerName = System.Environment.MachineName;
            Level      = ErrorLevel.error;

            Exception        = new SentryException(e);
            Exception.Module = e.Source;
            Exception.Type   = e.GetType().Name;
            Exception.Value  = e.Message;

            StackTrace = new SentryStacktrace(e);
            if (StackTrace.Frames.Count == 0)
            {
                StackTrace = null;
            }
        }
        public void Constructor_ExceptionWithFrames_FramesAreAsExpected()
        {
            var exception = TestHelper.GetException();
            SentryStacktrace stacktrace = new SentryStacktrace(exception);

            Console.WriteLine(exception);

            Assert.That(stacktrace.Frames, Is.Not.Null);
            Assert.That(stacktrace.Frames, Has.Length.EqualTo(2));
            Assert.That(stacktrace.Frames[0].Function, Is.EqualTo("PerformDivideByZero"));
            Assert.That(stacktrace.Frames[1].Function, Is.EqualTo("GetException"));
        }
        public SentryException(Exception e)
        {
            this.Module = e.Source;
            this.Type = e.Message;
            this.Value = e.Message;

            this.Stacktrace = new SentryStacktrace(e);
            if (this.Stacktrace.Frames == null || this.Stacktrace.Frames.Length == 0)
            {
                this.Stacktrace = null;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SentryException"/> class.
        /// </summary>
        /// <param name="e">The <see cref="Exception"/>.</param>
        public SentryException(Exception e)
        {
            Module = e.Source;
            Type = e.Message;
            Value = e.Message;

            Stacktrace = new SentryStacktrace(e);
            if (Stacktrace.Frames == null || Stacktrace.Frames.Length == 0)
            {
                Stacktrace = null;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SentryException"/> class.
        /// </summary>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public SentryException(Exception exception)
        {
            if (exception == null)
                return;

            this.message = exception.Message;
            Module = exception.Source;
            Type = exception.GetType().FullName;
            Value = exception.Message;

            Stacktrace = new SentryStacktrace(exception);
            if (Stacktrace.Frames == null || Stacktrace.Frames.Length == 0)
                Stacktrace = null;
        }
Beispiel #12
0
        public JsonPacket(string project, string log, string stack, LogType logType)
        {
            Initialize();
            Message = log;

            Project    = project;
            ServerName = System.Environment.MachineName;
            Level      = ErrorLevel.error;

            Exception        = new SentryException(log, stack, logType);
            Exception.Module = log;
            Exception.Type   = logType.ToString();
            Exception.Value  = stack;

            StackTrace = null;
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SentryException"/> class.
        /// </summary>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public SentryException(Exception exception)
        {
            if (exception == null)
            {
                return;
            }

            this.message = exception.Message;
            Module       = exception.Source;
            Type         = exception.GetType().FullName;
            Value        = exception.Message;

            Stacktrace = new SentryStacktrace(exception);
            if (Stacktrace.Frames == null || Stacktrace.Frames.Length == 0)
            {
                Stacktrace = null;
            }
        }
Beispiel #14
0
        public JsonPacket(string project, Exception e)
        {
            Initialize();
            Message = e.Message;

            if (e.TargetSite != null)
            {
                Culprit = String.Format("{0}.{1}", e.TargetSite.ReflectedType.FullName, e.TargetSite.Name);
            }

            Project = project;
            ServerName = System.Environment.MachineName;

            Exception = new SentryException(e);
            Exception.Module = e.Source;
            Exception.Value = e.Message;

            StackTrace = new SentryStacktrace(e);
        }
Beispiel #15
0
        public JsonPacket(string project, Exception e)
        {
            Initialize();
            Message = e.Message;

            if (e.TargetSite != null)
            {
                Culprit = String.Format("{0}.{1}", e.TargetSite.ReflectedType.FullName, e.TargetSite.Name);
            }

            Project    = project;
            ServerName = System.Environment.MachineName;

            Exception        = new SentryException(e);
            Exception.Module = e.Source;
            Exception.Value  = e.Message;

            StackTrace = new SentryStacktrace(e);
        }
        public void Constructor_NullException_DoesNotThrow()
        {
            SentryStacktrace stacktrace = new SentryStacktrace(null);

            Assert.That(stacktrace.Frames, Is.Null);
        }