Пример #1
0
        public static ErrorFormatter CreateDefault()
        {
            var f = new ErrorFormatter();

            f.Formatters.Add((e, o) => DotvvmMarkupErrorSection.Create(e));
            f.Formatters.Add((e, o) => new ExceptionSectionFormatter {
                Exception = f.LoadException(e)
            });
            f.Formatters.Add((e, o) => DictionarySection.Create("Cookies", "cookies", o.Request.Cookies));
            f.Formatters.Add((e, o) => DictionarySection.Create("Request Headers", "reqHeaders", o.Request.Headers));
            f.AddInfoLoader <ReflectionTypeLoadException>(e => new ExceptionAdditionalInfo
            {
                Title   = "Loader Exceptions",
                Objects = e.LoaderExceptions.Select(lde => lde.GetType().Name + ": " + lde.Message).ToArray(),
                Display = ExceptionAdditionalInfo.DisplayMode.ToString
            });
            f.AddInfoLoader <DotvvmCompilationException>(e =>
            {
                var info = new ExceptionAdditionalInfo()
                {
                    Title   = "DotVVM Compiler",
                    Objects = null,
                    Display = ExceptionAdditionalInfo.DisplayMode.ToString
                };
                if (e.Tokens != null && e.Tokens.Any())
                {
                    info.Objects = new object[]
                    {
                        $"Error in '{string.Concat(e.Tokens.Select(t => t.Text))}' at line {e.Tokens.First().LineNumber} in {e.SystemFileName}"
                    };
                }
                return(info);
            });

            f.AddInfoCollectionLoader <InvalidCommandInvocationException>(e =>
            {
                if (e.AdditionData == null || !e.AdditionData.Any())
                {
                    return(null);
                }
                var infos = new List <ExceptionAdditionalInfo>();
                foreach (var data in e.AdditionData)
                {
                    infos.Add(new ExceptionAdditionalInfo()
                    {
                        Title   = data.Key,
                        Objects = data.Value,
                        Display = ExceptionAdditionalInfo.DisplayMode.ToHtmlList
                    });
                }
                return(infos);
            });

            return(f);
        }
Пример #2
0
        public string ErrorHtml(Exception exception, IHttpContext context)
        {
            var template = new ErrorPageTemplate();

            template.Formatters = Formatters.Select(f => f(exception, context))
                                  .Concat(context.GetEnvironmentTabs().Select(o => DictionarySection.Create(o.Item1, "env_" + o.Item1.GetHashCode(), o.Item2)))
                                  .Where(t => t != null).ToArray();
            template.ErrorCode        = context.Response.StatusCode;
            template.ErrorDescription = "Unhandled exception occured";
            template.Summary          = exception.GetType().FullName + ": " + LimitLength(exception.Message, 600);

            return(template.TransformText());
        }
Пример #3
0
        public static ErrorFormatter CreateDefault()
        {
            var f = new ErrorFormatter();

            f.Formatters.Add((e, o) => DotvvmMarkupErrorSection.Create(e));
            f.Formatters.Add((e, o) => new ExceptionSectionFormatter {
                Exception = f.LoadException(e)
            });
            f.Formatters.Add((e, o) => DictionarySection.Create("Cookies", "cookies", o.Request.Cookies));
            f.Formatters.Add((e, o) => DictionarySection.Create("Request Headers", "reqHeaders", o.Request.Headers));
            f.Formatters.Add((e, o) => DictionarySection.Create("Environment", "env", o.Environment));
            f.AddInfoLoader <ReflectionTypeLoadException>(e => new ExceptionAdditionalInfo
            {
                Title   = "Loader Exceptions",
                Objects = e.LoaderExceptions.Select(lde => lde.GetType().Name + ": " + lde.Message).ToArray(),
                Display = ExceptionAdditionalInfo.DisplayMode.ToString
            });
            f.AddInfoLoader <DotvvmCompilationException>(e =>
            {
                var info = new ExceptionAdditionalInfo()
                {
                    Title   = "DotVVM Compiler",
                    Objects = null,
                    Display = ExceptionAdditionalInfo.DisplayMode.ToString
                };
                if (e.Tokens != null && e.Tokens.Any())
                {
                    info.Objects = new object[]
                    {
                        $"Error in '{string.Concat(e.Tokens.Select(t => t.Text))}' at line {e.Tokens.First().LineNumber} in {e.SystemFileName}"
                    };
                }
                return(info);
            });

            return(f);
        }
Пример #4
0
        public static ErrorFormatter CreateDefault()
        {
            var f = new ErrorFormatter();

            f.Formatters.Add((e, o) => DotvvmMarkupErrorSection.Create(e));
            f.Formatters.Add((e, o) => new ExceptionSectionFormatter(f.LoadException(e), "Raw Stack Trace", "raw_stack_trace"));
            f.Formatters.Add((e, o) => DictionarySection.Create("Cookies", "cookies", o.Request.Cookies));
            f.Formatters.Add((e, o) => DictionarySection.Create("Request Headers", "reqHeaders", o.Request.Headers));
            f.Formatters.Add((e, o) => {
                var b = e.AllInnerExceptions().OfType <BindingPropertyException>().Select(a => a.Binding).OfType <ICloneableBinding>().FirstOrDefault();
                if (b == null)
                {
                    return(null);
                }
                return(DictionarySection.Create("Binding", "binding",
                                                new [] { new KeyValuePair <object, object>("Type", b.GetType().FullName) }
                                                .Concat(
                                                    b.GetAllComputedProperties()
                                                    .Select(a => StripBindingProperty(a.GetType().Name, a))
                                                    .Select(a => new KeyValuePair <object, object>(a.name, a.value))
                                                    ).ToArray()));
            });
            f.AddInfoLoader <ReflectionTypeLoadException>(e => new ExceptionAdditionalInfo {
                Title   = "Loader Exceptions",
                Objects = e.LoaderExceptions.Select(lde => lde.GetType().Name + ": " + lde.Message).ToArray(),
                Display = ExceptionAdditionalInfo.DisplayMode.ToString
            });
            f.AddInfoLoader <DotvvmCompilationException>(e => {
                var info = new ExceptionAdditionalInfo()
                {
                    Title   = "DotVVM Compiler",
                    Objects = null,
                    Display = ExceptionAdditionalInfo.DisplayMode.ToString
                };
                if (e.Tokens != null && e.Tokens.Any())
                {
                    info.Objects = new object[]
                    {
                        $"Error in '{string.Concat(e.Tokens.Select(t => t.Text))}' at line {e.Tokens.First().LineNumber} in {e.SystemFileName}"
                    };
                }
                return(info);
            });

            f.AddInfoCollectionLoader <InvalidCommandInvocationException>(e => {
                if (e.AdditionData == null || !e.AdditionData.Any())
                {
                    return(null);
                }
                var infos = new List <ExceptionAdditionalInfo>();
                foreach (var data in e.AdditionData)
                {
                    infos.Add(new ExceptionAdditionalInfo()
                    {
                        Title   = data.Key,
                        Objects = data.Value,
                        Display = ExceptionAdditionalInfo.DisplayMode.ToHtmlList
                    });
                }
                return(infos);
            });

            return(f);
        }