Esempio n. 1
0
        private void UpdateExceptions(Exception exception)
        {
            // collect the set of exceptions detail info from the passed in exception
            List <ExceptionDetails> exceptions = new List <ExceptionDetails>();

            this.ConvertExceptionTree(exception, null, exceptions);

            // trim if we have too many, also add a custom exception to let the user know we're trimed
            if (exceptions.Count > Constants.MaxExceptionCountToSave)
            {
                // TODO: when we localize these messages, we should consider not using InvariantCulture
                // create our "message" exception.
                InnerExceptionCountExceededException countExceededException = new InnerExceptionCountExceededException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "The number of inner exceptions was {0} which is larger than {1}, the maximum number allowed during transmission. All but the first {1} have been dropped.",
                        exceptions.Count,
                        Constants.MaxExceptionCountToSave));

                // remove all but the first N exceptions
                exceptions.RemoveRange(Constants.MaxExceptionCountToSave, exceptions.Count - Constants.MaxExceptionCountToSave);

                // we'll add our new exception and parent it to the root exception (first one in the list)
                exceptions.Add(ExceptionConverter.ConvertToExceptionDetails(countExceededException, exceptions[0]));
            }

            this.Data.exceptions = exceptions;
        }
Esempio n. 2
0
            object YieldSimple()
            {
                object res;

                switch ((char)myBytes[curIndex++])
                {
                // simple ops to be read in
                case 'i': res = ReadInt(); break;

                case 'l': res = ReadBigInteger(); break;

                case 'T': res = Ops.TRUE; break;

                case 'F': res = Ops.FALSE; break;

                case 'f': res = ReadFloat(); break;

                case 't': res = ReadAsciiString(); break;

                case 'u': res = ReadUnicodeString(); break;

                case 'S': res = ExceptionConverter.GetPythonExceptionByName("StopIteration"); break;

                case 'N': res = null; break;

                case 'x': res = ReadComplex(); break;

                case 's': res = ReadBuffer(); break;

                case 'I': res = ReadLong(); break;

                default: throw Ops.ValueError("bad marshal data");
                }
                return(res);
            }
        /// <summary>
        /// Set parsedStack from an array of StackFrame objects.
        /// </summary>
        public void SetParsedStack(System.Diagnostics.StackFrame[] frames)
        {
            List <StackFrame> orderedStackTrace = new List <StackFrame>();

            if (this.Exceptions != null && this.Exceptions.Count > 0)
            {
                if (frames != null && frames.Length > 0)
                {
                    int stackLength = 0;

                    this.Exceptions[0].parsedStack  = new List <StackFrame>();
                    this.Exceptions[0].hasFullStack = true;

                    for (int level = 0; level < frames.Length; level++)
                    {
                        StackFrame sf = ExceptionConverter.GetStackFrame(frames[level], level);

                        stackLength += ExceptionConverter.GetStackFrameLength(sf);

                        if (stackLength > ExceptionConverter.MaxParsedStackLength)
                        {
                            this.Exceptions[0].hasFullStack = false;
                            break;
                        }

                        this.Exceptions[0].parsedStack.Add(sf);
                    }
                }
            }
        }
        public void ConvertsNestedExceptions()
        {
            // This will generate 3 nested exceptions
            var nestedExceptions = GenerateNestedExceptions();

            var message    = ExceptionUtility.GetMessage(nestedExceptions);
            var stackTrace = ExceptionUtility.GetStackTrace(nestedExceptions);

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(nestedExceptions.GetType().FullName, message, stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(3, taskExceptions.Length);

            Assert.Equal(nestedExceptions.GetType().FullName, taskExceptions[0].Type);
            Assert.Equal(nestedExceptions.Message, taskExceptions[0].Message);
            Assert.Equal(nestedExceptions.StackTrace, taskExceptions[0].StackTrace);

            Assert.Equal(nestedExceptions.InnerException.GetType().FullName, taskExceptions[1].Type);
            Assert.Equal(nestedExceptions.InnerException.Message, taskExceptions[1].Message);
            Assert.Equal(nestedExceptions.InnerException.StackTrace, taskExceptions[1].StackTrace);

            Assert.Equal(nestedExceptions.InnerException.InnerException.GetType().FullName, taskExceptions[2].Type);
            Assert.Equal(nestedExceptions.InnerException.InnerException.Message, taskExceptions[2].Message);
            Assert.Equal(nestedExceptions.InnerException.InnerException.StackTrace, taskExceptions[2].StackTrace);
        }
        public void SameTypeInnerErrorOfNonFulcrumType()
        {
            FulcrumApplication.Context.CorrelationId = Guid.NewGuid().ToString();
            var innerFulcrumError = new FulcrumError
            {
                TechnicalMessage = Guid.NewGuid().ToString(),
                InstanceId       = Guid.NewGuid().ToString(),
                Type             = "NotFulcrum"
            };
            var fulcrumError = new FulcrumError
            {
                Type                         = FulcrumConflictException.ExceptionType,
                TechnicalMessage             = Guid.NewGuid().ToString(),
                FriendlyMessage              = Guid.NewGuid().ToString(),
                InstanceId                   = Guid.NewGuid().ToString(),
                CorrelationId                = Guid.NewGuid().ToString(),
                Code                         = Guid.NewGuid().ToString(),
                ErrorLocation                = Guid.NewGuid().ToString(),
                IsRetryMeaningful            = true,
                MoreInfoUrl                  = Guid.NewGuid().ToString(),
                RecommendedWaitTimeInSeconds = 100.0,
                ServerTechnicalName          = Guid.NewGuid().ToString(),
                InnerError                   = innerFulcrumError,
                InnerInstanceId              = innerFulcrumError.InstanceId
            };
            var fulcrumException = ExceptionConverter.ToFulcrumException(fulcrumError);

            // Inner exception
            Assert.IsNull(fulcrumException.InnerException);
        }
        public void MultipleAfterTestExceptionsConvertedInReverseThrownOrder()
        {
            var afterExceptions = new Exception[3];

            afterExceptions[0] = GenerateSingleException();
            afterExceptions[1] = GenerateSingleException2();
            afterExceptions[2] = GenerateSingleException3();
            var exception = new AfterTestException(afterExceptions);

            var message    = ExceptionUtility.GetMessage(exception);
            var stackTrace = ExceptionUtility.GetStackTrace(exception);

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(exception.GetType().FullName, message,
                                                                         stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(3, taskExceptions.Length);

            Assert.Equal(afterExceptions[0].GetType().FullName, taskExceptions[2].Type);
            Assert.Equal(afterExceptions[0].Message, taskExceptions[2].Message);
            Assert.Equal(afterExceptions[0].StackTrace, taskExceptions[2].StackTrace);

            Assert.Equal(afterExceptions[1].GetType().FullName, taskExceptions[1].Type);
            Assert.Equal(afterExceptions[1].Message, taskExceptions[1].Message);
            Assert.Equal(afterExceptions[1].StackTrace, taskExceptions[1].StackTrace);

            Assert.Equal(afterExceptions[2].GetType().FullName, taskExceptions[0].Type);
            Assert.Equal(afterExceptions[2].Message, taskExceptions[0].Message);
            Assert.Equal(afterExceptions[2].StackTrace, taskExceptions[0].StackTrace);

            // TODO: RS6 uses full exception name. Does previous versions?
            Assert.Equal("Xunit.Sdk.AfterTestException: One or more exceptions were thrown from After methods during test cleanup", simplifiedMessage);
        }
Esempio n. 7
0
        protected virtual void Application_BeginRequest()
        {
            if (_startupError != null)
            {
                try
                {
                    var exception = new FulcrumResourceException($"FATAL ERROR IN STARTUP for {FulcrumApplication.Setup?.Name}" +
                                                                 $" (InstanceId: {Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}):" +
                                                                 $" {_startupError.Message}. Check fallback logs for details.");
                    var error      = ExceptionConverter.ToFulcrumError(exception, true);
                    var statusCode = ExceptionConverter.ToHttpStatusCode(error);

                    // TrySkipIisCustomErrors = true is important! Without it, IIS sets it's own response content.
                    // See https://weblog.west-wind.com/posts/2017/jun/01/bypassing-iis-error-messages-in-aspnet
                    Response.TrySkipIisCustomErrors = true;

                    Response.StatusCode  = statusCode != null ? (int)statusCode : (int)HttpStatusCode.InternalServerError;
                    Response.ContentType = "application/json";
                    Response.Output.Write(JsonConvert.SerializeObject(error));
                }
                catch (Exception e)
                {
                    LogHelper.FallbackSafeLog(LogSeverityLevel.Critical, "Failure in Application_BeginRequest", e);
                    throw;
                }
            }
        }
Esempio n. 8
0
        public static object GetFileStats(string path)
        {
            StatResult sr = new StatResult();

            try {
                sr.atime = (long)Directory.GetLastAccessTime(path).Subtract(DateTime.MinValue).TotalSeconds;
                sr.ctime = (long)Directory.GetCreationTime(path).Subtract(DateTime.MinValue).TotalSeconds;
                sr.mtime = (long)Directory.GetLastWriteTime(path).Subtract(DateTime.MinValue).TotalSeconds;

                if (Directory.Exists(path))
                {
                    sr.mode = 0x4000;
                }
                else if (File.Exists(path))
                {
                    FileInfo fi = new FileInfo(path);
                    sr.size = fi.Length;
                    sr.mode = 0x8000; //@TODO - Set other valid mode types (S_IFCHR, S_IFBLK, S_IFIFO, S_IFLNK, S_IFSOCK) (to the degree that they apply)
                }
                else
                {
                    throw new IOException("file does not exist");
                }
            } catch (Exception e) {
                throw ExceptionConverter.CreateThrowable(error, e.Message);
            }

            return(sr);
        }
Esempio n. 9
0
    protected override JsonConverter ResolveContractConverter(Type objectType)
    {
        if (objectType is null)
        {
            throw new ArgumentNullException(nameof(objectType));
        }

        var converter = converters.FirstOrDefault(c => c.CanConvert(objectType));

        if (converter is not null)
        {
            return(converter);
        }
        else if (typeof(Exception).IsAssignableFrom(objectType))
        {
            converter = new ExceptionConverter();
        }
        else if (typeof(NameValueCollection).IsAssignableFrom(objectType))
        {
            converter = new NameValueCollectionConverter();
        }
        else if (objectType.IsEnum)
        {
            converter = new StringEnumConverter();
        }
        else
        {
            converter = base.ResolveContractConverter(objectType);
        }

        return(converter);
    }
        public BugsnagClient(Context context, string apiKey, bool enableMetrics = true)
        {
            if (context == null)
                throw new ArgumentNullException ("context");
            if (apiKey == null)
                throw new ArgumentNullException ("apiKey");

            context = context.ApplicationContext;

            this.apiKey = apiKey;
            sendMetrics = enableMetrics;
            ReleaseStage = GuessReleaseStage (context);
            AutoNotify = true;

            // Install exception handlers
            interceptors = new IDisposable[] {
                new AppDomainInterceptor (this),
                new TaskSchedulerInterceptor (this),
                new AndroidInterceptor (this),
            };

            state = new StateCacher (new StateReporter (this, context));
            activityTracker = new ActivityTracker ();
            exceptionConverter = new ExceptionConverter (this);
            notifier = new Notifier (this, MakeErrorCacheDir (context));
        }
            public async Task InvokeAsync(HttpContext context)
            {
                context.Response.StatusCode = _statusCode;
                FulcrumException fulcrumException = null;

                if (_statusCode >= 500)
                {
                    fulcrumException = new FulcrumAssertionFailedException("Internal error message");
                }
                else if (_statusCode >= 400)
                {
                    fulcrumException = new FulcrumServiceContractException("Client error message");
                }

                if (_statusCode >= 400)
                {
                    await context.Response.WriteAsync("Test");

                    context.Response.Body        = new MemoryStream();
                    context.Response.ContentType = "application/json";
                    var fulcrumError = ExceptionConverter.ToFulcrumError(fulcrumException);
                    var content      = ExceptionConverter.ToJsonString(fulcrumError, Formatting.Indented);
                    await context.Response.WriteAsync(content);
                }
            }
        public void RemovesTargetInvocationExceptionFromHeadOfList()
        {
            var nestedExceptions = GenerateTargetInvocationException();

            Assert.IsType <TargetInvocationException>(nestedExceptions);

            var message    = ExceptionUtility.GetMessage(nestedExceptions);
            var stackTrace = ExceptionUtility.GetStackTrace(nestedExceptions);

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(nestedExceptions.GetType().FullName, message, stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(3, taskExceptions.Length);

            Assert.NotEqual(typeof(TargetInvocationException).FullName, taskExceptions[0].Type);

            nestedExceptions = nestedExceptions.InnerException;

            Assert.Equal(nestedExceptions.GetType().FullName, taskExceptions[0].Type);
            Assert.Equal(nestedExceptions.Message, taskExceptions[0].Message);
            Assert.Equal(nestedExceptions.StackTrace, taskExceptions[0].StackTrace);

            Assert.Equal(nestedExceptions.InnerException.GetType().FullName, taskExceptions[1].Type);
            Assert.Equal(nestedExceptions.InnerException.Message, taskExceptions[1].Message);
            Assert.Equal(nestedExceptions.InnerException.StackTrace, taskExceptions[1].StackTrace);

            Assert.Equal(nestedExceptions.InnerException.InnerException.GetType().FullName, taskExceptions[2].Type);
            Assert.Equal(nestedExceptions.InnerException.InnerException.Message, taskExceptions[2].Message);
            Assert.Equal(nestedExceptions.InnerException.InnerException.StackTrace, taskExceptions[2].StackTrace);
        }
Esempio n. 13
0
        private void ConvertExceptionTree(Exception exception, ExceptionDetails parentExceptionDetails, List <ExceptionDetails> exceptions)
        {
            if (exception == null)
            {
                exception = new Exception(Utils.PopulateRequiredStringValue(null, "message", typeof(ExceptionTelemetry).FullName));
            }

            ExceptionDetails exceptionDetails = ExceptionConverter.ConvertToExceptionDetails(exception, parentExceptionDetails);

            // For upper level exception see if Message was provided and do not use exceptiom.message in that case
            if (parentExceptionDetails == null && !string.IsNullOrWhiteSpace(this.Message))
            {
                exceptionDetails.message = this.Message;
            }

            exceptions.Add(exceptionDetails);

            AggregateException aggregate = exception as AggregateException;

            if (aggregate != null)
            {
                foreach (Exception inner in aggregate.InnerExceptions)
                {
                    this.ConvertExceptionTree(inner, exceptionDetails, exceptions);
                }
            }
            else if (exception.InnerException != null)
            {
                this.ConvertExceptionTree(exception.InnerException, exceptionDetails, exceptions);
            }
        }
Esempio n. 14
0
 public static RE_Pattern Compile(object pattern, object flags)
 {
     try {
         return(new RE_Pattern(ValidatePattern(pattern), Converter.ConvertToInt32(flags)));
     } catch (ArgumentException e) {
         throw ExceptionConverter.CreateThrowable(error, e.Message);
     }
 }
        private static StatusAndContent ToStatusAndContent(Exception e)
        {
            if (e is RequestAcceptedException acceptedException)
            {
                var acceptedContent = new RequestAcceptedContent()
                {
                    RequestId           = acceptedException.RequestId,
                    PollingUrl          = acceptedException.PollingUrl,
                    RegisterCallbackUrl = acceptedException.RegisterCallbackUrl
                };
                FulcrumAssert.IsValidated(acceptedContent, CodeLocation.AsString());
                return(new StatusAndContent
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    StatusCode = HttpStatusCode.Accepted,
                    Content = JsonConvert.SerializeObject(acceptedContent)
                });
            }
            if (e is RequestPostponedException postponedException)
            {
                var postponedContent = new RequestPostponedContent()
                {
                    TryAgain              = postponedException.TryAgain,
                    WaitingForRequestIds  = postponedException.WaitingForRequestIds,
                    ReentryAuthentication = postponedException.ReentryAuthentication
                };
                FulcrumAssert.IsValidated(postponedContent, CodeLocation.AsString());
                return(new StatusAndContent
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    StatusCode = HttpStatusCode.Accepted,
                    Content = JsonConvert.SerializeObject(postponedContent)
                });
            }
            if (!(e is FulcrumException fulcrumException))
            {
                var message = $"Application threw an exception that didn't inherit from {typeof(FulcrumException)}.\r{e.GetType().FullName}: {e.Message}\rFull exception:\r{e}";
                Log.LogError(message, e);
                fulcrumException = new FulcrumAssertionFailedException(message, e);
            }

            var error      = ExceptionConverter.ToFulcrumError(fulcrumException, true);
            var statusCode = ExceptionConverter.ToHttpStatusCode(error);

            FulcrumAssert.IsNotNull(statusCode, CodeLocation.AsString());
            Log.LogVerbose(
                $"{error.Type} => HTTP status {statusCode}");
            var content = ExceptionConverter.ToJsonString(error, Formatting.Indented);

            return(new StatusAndContent
            {
                // ReSharper disable once PossibleInvalidOperationException
                StatusCode = statusCode.Value,
                Content = content
            });
        }
Esempio n. 16
0
        private void DumpStackTraces(Exception e, FilterStackFrame fsf, ref bool printedHeader)
        {
            if (PythonEngine.options.ExceptionDetail)
            {
                if (!printedHeader)
                {
                    MyConsole.WriteLine(e.Message, Style.Error);
                    printedHeader = true;
                }
                List <System.Diagnostics.StackTrace> traces = ExceptionConverter.GetExceptionStackTraces(e);

                if (traces != null)
                {
                    for (int i = 0; i < traces.Count; i++)
                    {
                        for (int j = 0; j < traces[i].FrameCount; j++)
                        {
                            StackFrame curFrame = traces[i].GetFrame(j);
                            if (fsf == null || fsf(curFrame))
                            {
                                MyConsole.WriteLine(curFrame.ToString(), Style.Error);
                            }
                        }
                    }
                }

                MyConsole.WriteLine(e.StackTrace.ToString(), Style.Error);
                if (e.InnerException != null)
                {
                    DumpStackTraces(e.InnerException, ref printedHeader);
                }
            }
            else
            {
                // dump inner most exception first, followed by outer most.
                if (e.InnerException != null)
                {
                    DumpStackTraces(e.InnerException, ref printedHeader);
                }

                if (!printedHeader)
                {
                    MyConsole.WriteLine("Traceback (most recent call last):", Style.Error);
                    printedHeader = true;
                }
                DumpStackTrace(new StackTrace(e, true), fsf);
                List <StackTrace> traces = ExceptionConverter.GetExceptionStackTraces(e);
                if (traces != null && traces.Count > 0)
                {
                    for (int i = 0; i < traces.Count; i++)
                    {
                        DumpStackTrace(traces[i], fsf);
                    }
                }
            }
        }
        public void ConvertedTypeNoInnerError()
        {
            FulcrumApplication.Context.CorrelationId = Guid.NewGuid().ToString();
            var fulcrumError = new FulcrumError
            {
                Type                         = FulcrumAssertionFailedException.ExceptionType,
                TechnicalMessage             = Guid.NewGuid().ToString(),
                FriendlyMessage              = Guid.NewGuid().ToString(),
                InstanceId                   = Guid.NewGuid().ToString(),
                CorrelationId                = Guid.NewGuid().ToString(),
                Code                         = Guid.NewGuid().ToString(),
                ErrorLocation                = Guid.NewGuid().ToString(),
                IsRetryMeaningful            = true,
                MoreInfoUrl                  = Guid.NewGuid().ToString(),
                RecommendedWaitTimeInSeconds = 100.0,
                ServerTechnicalName          = Guid.NewGuid().ToString()
            };
            var fulcrumException = ExceptionConverter.ToFulcrumException(fulcrumError);

            Assert.AreNotEqual(fulcrumError.Type, fulcrumException.Type);

            // Equal
            Assert.IsNotNull(fulcrumException);
            Assert.AreEqual(fulcrumError.TechnicalMessage, fulcrumException.TechnicalMessage);
            Assert.AreEqual(fulcrumError.TechnicalMessage, fulcrumException.Message);
            Assert.AreEqual(fulcrumError.RecommendedWaitTimeInSeconds, fulcrumException.RecommendedWaitTimeInSeconds);
            Assert.AreEqual(fulcrumError.IsRetryMeaningful, fulcrumException.IsRetryMeaningful);

            // NOT equal
            Assert.AreNotEqual(fulcrumError.CorrelationId, fulcrumException.CorrelationId);
            Assert.AreNotEqual(fulcrumError.ServerTechnicalName, fulcrumException.ServerTechnicalName);
            Assert.AreNotEqual(fulcrumError.Code, fulcrumException.Code);
            Assert.AreNotEqual(fulcrumError.FriendlyMessage, fulcrumException.FriendlyMessage);
            Assert.AreEqual(FulcrumResourceException.ExceptionType, fulcrumException.Type);
            Assert.AreNotEqual(fulcrumError.InstanceId, fulcrumException.InstanceId);
            Assert.AreNotEqual(fulcrumError.MoreInfoUrl, fulcrumException.MoreInfoUrl);
            Assert.IsNull(fulcrumException.ErrorLocation);

            // Inner exception
            Assert.IsNotNull(fulcrumException.InnerException);
            var innerFulcrumException = fulcrumException.InnerException as FulcrumException;

            Assert.IsNotNull(innerFulcrumException);
            Assert.AreEqual(fulcrumError.InstanceId, innerFulcrumException.InstanceId);
            Assert.AreEqual(fulcrumError.InnerInstanceId, innerFulcrumException.InnerInstanceId);
            Assert.AreEqual(fulcrumError.ServerTechnicalName, innerFulcrumException.ServerTechnicalName);
            Assert.AreEqual(fulcrumError.CorrelationId, innerFulcrumException.CorrelationId);
            Assert.AreEqual(fulcrumError.Code, innerFulcrumException.Code);
            Assert.AreEqual(fulcrumError.IsRetryMeaningful, innerFulcrumException.IsRetryMeaningful);
            Assert.AreEqual(fulcrumError.FriendlyMessage, innerFulcrumException.FriendlyMessage);
            Assert.AreEqual(fulcrumError.Type, innerFulcrumException.Type);
            Assert.AreEqual(fulcrumError.InstanceId, innerFulcrumException.InstanceId);
            Assert.AreEqual(fulcrumError.MoreInfoUrl, innerFulcrumException.MoreInfoUrl);
            Assert.AreEqual(fulcrumError.ErrorLocation, innerFulcrumException.ErrorLocation);
        }
        public void ConvertUnknownType()
        {
            var fulcrumError = new FulcrumError
            {
                Type = "UnknownErrorType"
            };
            var fulcrumException = ExceptionConverter.ToFulcrumException(fulcrumError);

            Assert.IsNotNull(fulcrumException);
            Assert.AreEqual(FulcrumAssertionFailedException.ExceptionType, fulcrumException.Type);
        }
Esempio n. 19
0
 public RE_Pattern(object pattern, int flags)
 {
     pre = PreParseRegex(ValidatePattern(pattern));
     try {
         RegexOptions opts = FlagsToOption(flags);
         this.re = new Regex(pre.Pattern, opts);
     } catch (ArgumentException e) {
         throw ExceptionConverter.CreateThrowable(error, e.Message);
     }
     this.compileFlags = flags;
 }
Esempio n. 20
0
        public void DumpException(Exception e)
        {
            object pythonEx = ExceptionConverter.ToPython(e);

            DumpStackTraces(e);
            DumpPythonException(pythonEx);
            if (PythonEngine.options.ShowCLSExceptions)
            {
                DumpCLSException(e);
            }
        }
        private static void Verify(string sourceType, string targetType)
        {
            var fulcrumError = new FulcrumError
            {
                Type = sourceType
            };
            var fulcrumException = ExceptionConverter.ToFulcrumException(fulcrumError);

            Assert.IsNotNull(fulcrumException);
            Assert.AreEqual(targetType, fulcrumException.Type);
        }
Esempio n. 22
0
        public async Task ConvertEmpty()
        {
            var responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent("", Encoding.UTF8)
            };
            var result = await ExceptionConverter.ToFulcrumExceptionAsync(responseMessage);

            Assert.IsNotNull(result);
            Assert.AreEqual(FulcrumContractException.ExceptionType, result.Type);
        }
Esempio n. 23
0
        public async Task Convert404()
        {
            var content         = "Not result FulcrumError";
            var responseMessage = new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                Content = new StringContent(content, Encoding.UTF8)
            };
            var result = await ExceptionConverter.ToFulcrumExceptionAsync(responseMessage);

            Assert.IsNotNull(result);
            Assert.AreEqual(FulcrumContractException.ExceptionType, result.Type);
        }
Esempio n. 24
0
        public async Task ContentIsUsed()
        {
            var responseBodyContent = Guid.NewGuid().ToString();
            var responseMessage     = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(responseBodyContent, Encoding.UTF8)
            };
            var fulcrumError = await ExceptionConverter.ToFulcrumErrorAsync(responseMessage);

            Assert.IsNotNull(fulcrumError);
            Assert.IsTrue(fulcrumError.TechnicalMessage.Contains(responseBodyContent));
        }
        public void DoesNotRemoveTargetInvocationExceptionIfOnlyException()
        {
            var exception = GenerateSingleTargetInvocationException();

            var message    = ExceptionUtility.GetMessage(exception);
            var stackTrace = ExceptionUtility.GetStackTrace(exception);

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(exception.GetType().FullName, message, stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(1, taskExceptions.Length);
        }
Esempio n. 26
0
        public async Task Convert402()
        {
            var content         = "Accepted FulcrumError";
            var responseMessage = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content = new StringContent(content, Encoding.UTF8)
            };
            var result = await ExceptionConverter.ToFulcrumExceptionAsync(responseMessage);

            Assert.IsNotNull(result);
#pragma warning disable 618
            Assert.AreEqual(FulcrumAcceptedException.ExceptionType, result.Type);
#pragma warning restore 618
        }
        public void SimplifiedMessageIsOutermostExceptionTypeShortNameAndMessage()
        {
            var nestedExceptions = GenerateNestedExceptions();

            var message    = ExceptionUtility.GetMessage(nestedExceptions);
            var stackTrace = ExceptionUtility.GetStackTrace(nestedExceptions);

            string simplifiedMessage;

            ExceptionConverter.ConvertExceptions(nestedExceptions.GetType().FullName, message, stackTrace, out simplifiedMessage);

            // TODO: RS6 uses full exception name. Does previous versions?
            Assert.Equal(nestedExceptions.GetType().FullName + ": " + nestedExceptions.Message, simplifiedMessage);
        }
Esempio n. 28
0
        public async Task ContentIsTruncated()
        {
            var responseBodyContent = new string('x', 1000);
            var responseMessage     = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(responseBodyContent, Encoding.UTF8)
            };
            var fulcrumError = await ExceptionConverter.ToFulcrumErrorAsync(responseMessage);

            Assert.IsNotNull(fulcrumError);
            Assert.IsTrue(fulcrumError.TechnicalMessage.Length < 1000);
            var smallContent = responseBodyContent.Substring(0, 100);

            Assert.IsTrue(fulcrumError.TechnicalMessage.Contains(smallContent));
        }
Esempio n. 29
0
        public async Task ConvertNotFulcrumErrorAndAccessAfter()
        {
            var content         = "Not result FulcrumError";
            var responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent(content, Encoding.UTF8)
            };
            var result = await ExceptionConverter.ToFulcrumExceptionAsync(responseMessage);

            Assert.IsNotNull(result);
            Assert.AreEqual(FulcrumContractException.ExceptionType, result.Type);
            var contentAfter = await responseMessage.Content.ReadAsStringAsync();

            Assert.AreEqual(content, contentAfter);
        }
        public void HandlesExceptionNotFormattedUsingExceptionUtility()
        {
            var singleException = GenerateSingleException();

            var message    = singleException.Message;
            var stackTrace = singleException.StackTrace;

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(singleException.GetType().FullName, message, stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(1, taskExceptions.Length);
            Assert.Equal(singleException.GetType().FullName, taskExceptions[0].Type);
            Assert.Equal(singleException.Message, taskExceptions[0].Message);
            Assert.Equal(singleException.StackTrace, taskExceptions[0].StackTrace);
        }
        public void ConvertsToSingleException()
        {
            var singleException = GenerateSingleException();

            var message    = ExceptionUtility.GetMessage(singleException);
            var stackTrace = ExceptionUtility.GetStackTrace(singleException);

            string simplifiedMessage;
            var    taskExceptions = ExceptionConverter.ConvertExceptions(singleException.GetType().FullName, message, stackTrace, out simplifiedMessage);

            Assert.NotNull(taskExceptions);
            Assert.Equal(1, taskExceptions.Length);
            Assert.Equal(singleException.GetType().FullName, taskExceptions[0].Type);
            Assert.Equal(singleException.Message, taskExceptions[0].Message);
            Assert.Equal(singleException.StackTrace, taskExceptions[0].StackTrace);
        }
        public BugsnagClient(string apiKey, bool enableMetrics = true)
        {
            if (apiKey == null)
                throw new ArgumentNullException ("apiKey");

            this.apiKey = apiKey;
            sendMetrics = enableMetrics;
            AutoNotify = true;

            // Install exception handlers
            interceptors = new IDisposable[] {
                new AppDomainInterceptor (this),
                new TaskSchedulerInterceptor (this),
            };

            state = new StateCacher (new StateReporter (this));
            stateTracker = new StateTracker ();
            exceptionConverter = new ExceptionConverter (this);
            notifier = new Notifier (this, MakeErrorCacheDir ());

            // Register observers init observer
            notifApplicationDidBecomeActive = NSNotificationCenter.DefaultCenter.AddObserver (
                UIApplication.DidBecomeActiveNotification, OnApplicationDidBecomeActive);
        }
Esempio n. 33
0
 public MailService()
 {
     var types = new[] { typeof(SmtpException) };
     _exceptionConverter = new ExceptionConverter(types, exception => new MailServiceException(exception));
 }
Esempio n. 34
0
 public void Setup()
 {
     _converter = new ExceptionConverter();
 }
 public override void TestFixtureSetUp()
 {
     var types = new[] { typeof(SmtpException) };
     _exceptionConverter = new ExceptionConverter(types, exception => new MailServiceException(exception));
 }
Esempio n. 36
0
 public void Teardown()
 {
     _converter = null;
 }
 private void SetFlagsAndExceptionInfo(int flags, ExceptionConverter converter, ExceptionEditor editor)
 {
     this.Flags = flags;
     this.exceptionConverter = converter;
     this.exceptionEditor = editor;
 }