Exemple #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);
        }
Exemple #2
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);
        }