public void Constructor_InvalidOperationException_TypeIsInvalidOperationException()
        {
            var exception = new InvalidOperationException("Invalid");
            var sentryException = new SentryException(exception);

            Assert.That(sentryException.Type, Is.EqualTo("System.InvalidOperationException"));
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonPacket"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public JsonPacket(string project, Exception exception)
            : this(project)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            Message = exception.Message;

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

            Exceptions = new List<SentryException>();

            for (Exception currentException = exception;
                 currentException != null;
                 currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException)
                {
                    Module = currentException.Source,
                    Type = currentException.GetType().Name,
                    Value = currentException.Message
                };

                Exceptions.Add(sentryException);
            }
        }
        public void Constructor_DivideByZeroException_StackTraceIsNotNull()
        {
            var exception = TestHelper.GetException();
            var sentryException = new SentryException(exception);

            Assert.That(sentryException.Stacktrace, Is.Not.Null);
        }
        public void Constructor_DivideByZeroException_ModuleEqualsUnitTests()
        {
            var exception = TestHelper.GetException();
            var sentryException = new SentryException(exception);

            Assert.That(sentryException.Module, Is.EqualTo("SharpRaven.UnitTests"));
        }
Example #5
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;
            }
        }
Example #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;

            Exceptions = new List<SentryException>();

            for (Exception currentException = e; currentException != null; currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException);
                sentryException.Module = currentException.Source;
                sentryException.Type = currentException.GetType().Name;
                sentryException.Value = currentException.Message;
                Exceptions.Add(sentryException);
            }
        }
        public void Constructor_InvalidOperationException_ValueIsEqualToMessage()
        {
            const string message = "Invalid";
            var exception = new InvalidOperationException(message);
            var sentryException = new SentryException(exception);

            Assert.That(sentryException.Value, Is.EqualTo(message));
        }
        public void Constructor_NullException_DoesNotThrow()
        {
            var sentryException = new SentryException(null);

            Assert.That(sentryException.Type, Is.Null);
            Assert.That(sentryException.Value, Is.Null);
            Assert.That(sentryException.Module, Is.Null);
            Assert.That(sentryException.Stacktrace, Is.Null);
        }
Example #9
0
 private void Write(SentryException exception)
 {
     writer.WritePropertyName("sentry.interfaces.Exception");
     writer.WriteStartObject();
     {
         Write("type", exception.Type);
         Write("value", exception.Message);
         Write("module", exception.Module);
     }
     writer.WriteEndObject();
 }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonPacket"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public JsonPacket(string project, Exception exception)
            : this(project)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Message = exception.Message;

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

            Exceptions = new List <SentryException>();

            for (Exception currentException = exception;
                 currentException != null;
                 currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException)
                {
                    Module = currentException.Source,
                    Type   = currentException.GetType().Name,
                    Value  = currentException.Message
                };

                Exceptions.Add(sentryException);
            }

            // ReflectionTypeLoadException doesn't contain much useful info in itself, and needs special handling
            ReflectionTypeLoadException reflectionTypeLoadException = exception as ReflectionTypeLoadException;
            if (reflectionTypeLoadException != null)
            {
                foreach (Exception loaderException in reflectionTypeLoadException.LoaderExceptions)
                {
                    SentryException sentryException = new SentryException(loaderException);

                    Exceptions.Add(sentryException);
                }
            }
        }
Example #11
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;
        }
Example #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;
        }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonPacket"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public JsonPacket(string project, Exception exception)
            : this(project)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            Message = exception.Message;

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

            Exceptions = new List<SentryException>();

            for (Exception currentException = exception;
                currentException != null;
                currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException)
                {
                    Module = currentException.Source,
                    Type = currentException.GetType().Name,
                    Value = currentException.Message
                };

                Exceptions.Add(sentryException);
            }

            // ReflectionTypeLoadException doesn't contain much useful info in itself, and needs special handling
            ReflectionTypeLoadException reflectionTypeLoadException = exception as ReflectionTypeLoadException;
            if (reflectionTypeLoadException != null)
            {
                foreach (Exception loaderException in reflectionTypeLoadException.LoaderExceptions)
                {
                    SentryException sentryException = new SentryException(loaderException);

                    Exceptions.Add(sentryException);
                }
            }
        }
Example #14
0
        private void Initialize(Exception exception)
        {
            Message = exception.Message;

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

            Exceptions = new List <SentryException>();

            for (Exception currentException = exception;
                 currentException != null;
                 currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException)
                {
                    Module = currentException.Source,
                    Type   = currentException.GetType().Name,
                    Value  = currentException.Message
                };

                Exceptions.Add(sentryException);
            }

            // ReflectionTypeLoadException doesn't contain much useful info in itself, and needs special handling
            ReflectionTypeLoadException reflectionTypeLoadException = exception as ReflectionTypeLoadException;

            if (reflectionTypeLoadException != null)
            {
                foreach (Exception loaderException in reflectionTypeLoadException.LoaderExceptions)
                {
                    SentryException sentryException = new SentryException(loaderException);

                    Exceptions.Add(sentryException);
                }
            }
        }
Example #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);
        }
Example #16
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);
        }
Example #17
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;
            Level = ErrorLevel.error;

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

            this.StackTrace = new SentryStacktrace(e);
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonPacket"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="exception">The <see cref="Exception"/>.</param>
        public JsonPacket(string project, Exception exception)
            : this(project)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            Message = exception.Message;

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

            Exceptions = new List <SentryException>();

            for (Exception currentException = exception;
                 currentException != null;
                 currentException = currentException.InnerException)
            {
                SentryException sentryException = new SentryException(currentException)
                {
                    Module = currentException.Source,
                    Type   = currentException.GetType().Name,
                    Value  = currentException.Message
                };

                Exceptions.Add(sentryException);
            }
        }
        public void ToString_StringIsEqualTo_ExceptionToString()
        {
            var exception = TestHelper.GetException();
            var sentryException = new SentryException(exception);
            string exceptionString = exception.ToString();
            string stacktraceString = sentryException.ToString();

            Console.WriteLine(exceptionString);
            Console.WriteLine();
            Console.WriteLine(stacktraceString);

            Assert.That(stacktraceString, Is.EqualTo(exceptionString));
        }
        public void Constructor_PrivateException_TypeIsPrivateException()
        {
            var exception = new PrivateException();
            var sentryException = new SentryException(exception);

            Assert.That(sentryException.Type, Is.EqualTo("SharpRaven.UnitTests.Data.PrivateException"));
        }