private static string ExceptionToString(ExecutionError error)
        {
            var locationStrings = error.Locations?.Select(loc => $"(Line: {loc.Line}, Column: {loc.Column})");
            var locations       = locationStrings != null?string.Join(", ", locationStrings) : string.Empty;

            return($"{error.Message}\nLocations: {locations}\n{error.ToString()}");
        }
    public void exposeExceptions()
    {
        var innerException = new ArgumentNullException(null, new ArgumentOutOfRangeException());
        var error          = new ExecutionError(innerException.Message, innerException);

        var info = new ErrorInfoProvider(new ErrorInfoProviderOptions {
            ExposeExceptionStackTrace = true
        }).GetInfo(error);

        info.Message.ShouldBe(error.ToString());
    }
示例#3
0
        public static void Throw(ExecutionError error)
        {
            var description = error.GetType()
                              .GetField(error.ToString())
                              .GetCustomAttributes(typeof(DescriptionAttribute), false)
                              .Cast <DescriptionAttribute>()
                              .Single()
                              .Description;

            throw new ExecutionException(description);
        }
示例#4
0
        /// <inheritdoc/>
        public virtual ErrorInfo GetInfo(ExecutionError executionError)
        {
            if (executionError == null)
            {
                throw new ArgumentNullException(nameof(executionError));
            }

            IDictionary <string, object> extensions = null;

            if (_options.ExposeExtensions)
            {
                var code  = _options.ExposeCode ? executionError.Code : null;
                var codes = _options.ExposeCodes ? GetCodesForError(executionError).ToList() : null;
                if (codes?.Count == 0)
                {
                    codes = null;
                }
                var number = _options.ExposeCode && executionError is ValidationError validationError ? validationError.Number : null;
                var data   = _options.ExposeData && executionError.Data?.Count > 0 ? executionError.Data : null;

                if (code != null || codes != null || data != null)
                {
                    extensions = new Dictionary <string, object>();
                    if (code != null)
                    {
                        extensions.Add("code", code);
                    }
                    if (codes != null)
                    {
                        extensions.Add("codes", codes);
                    }
                    if (number != null)
                    {
                        extensions.Add("number", number);
                    }
                    if (data != null)
                    {
                        extensions.Add("data", data);
                    }
                }
            }

            return(new ErrorInfo
            {
                Message = _options.ExposeExceptionStackTrace ? executionError.ToString() : executionError.Message,
                Extensions = extensions,
            });
        }