Skip to content

Commit

Permalink
Fix control prefixes in error page "Control Hierarchy" section
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Dec 28, 2024
1 parent 5b54b96 commit 92e9ac9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/Framework/Framework/Controls/DotvvmBindableObjectHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
Expand Down Expand Up @@ -484,14 +485,24 @@ static string ValueDebugString(object? value)

return toStringed;
}

internal static (string? prefix, string tagName) FormatControlName(DotvvmBindableObject control, DotvvmConfiguration? config)
{
var type = control.GetType();
if (type == typeof(HtmlGenericControl))
return (null, ((HtmlGenericControl)control).TagName!);

if (control is DotvvmMarkupControl && control.GetValue(Internal.MarkupFileNameProperty, inherit: false) is string markupFileName)
return FormatMarkupControlName(markupFileName, config);
return FormatControlName(type, config);
}
internal static (string? prefix, string tagName) FormatMarkupControlName(string fileName, DotvvmConfiguration? config)
{
var reg = config?.Markup.Controls.FirstOrDefault(c => c.Src?.Replace('\\', '/') == fileName.Replace('\\', '/'));
if (reg is { TagName.Length: >0 })
return (reg.TagPrefix, reg.TagName);
else
return (null, Path.GetFileNameWithoutExtension(fileName));
}
internal static (string? prefix, string tagName) FormatControlName(Type type, DotvvmConfiguration? config)
{
var reg = config?.Markup.Controls.FirstOrDefault(c => c.Namespace == type.Namespace && Type.GetType(c.Namespace + "." + type.Name + ", " + c.Assembly) == type) ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Configuration;
using Microsoft.Extensions.Logging;

namespace DotVVM.Framework.Hosting.ErrorPages
{
public class DotvvmErrorPageRenderer
{
private readonly ILogger<DotvvmErrorPageRenderer>? logger;
private readonly DotvvmConfiguration config;

public ErrorFormatter? Formatter { get; set; }

public DotvvmErrorPageRenderer(ILogger<DotvvmErrorPageRenderer>? logger = null)
public DotvvmErrorPageRenderer(DotvvmConfiguration config, ILogger<DotvvmErrorPageRenderer>? logger = null)
{
this.config = config;
this.logger = logger;
}

Expand Down Expand Up @@ -62,7 +65,7 @@ private static async Task RenderFallbackMessage(IHttpContext context, Exception

private ErrorFormatter CreateDefaultWithDemystifier()
{
var errorFormatter = ErrorFormatter.CreateDefault();
var errorFormatter = ErrorFormatter.CreateDefault(config);

var insertPosition = errorFormatter.Formatters.Count > 0 ? 1 : 0;

Expand Down
5 changes: 3 additions & 2 deletions src/Framework/Framework/Hosting/ErrorPages/ErrorFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using DotVVM.Framework.Binding;
using DotVVM.Framework.Binding.Expressions;
using DotVVM.Framework.Compilation;
using DotVVM.Framework.Configuration;
using DotVVM.Framework.Controls;
using DotVVM.Framework.Runtime;
using DotVVM.Framework.Runtime.Commands;
Expand Down Expand Up @@ -386,7 +387,7 @@ private static ExceptionModel LoadDemystifiedException(ErrorFormatter formatter,
}


public static ErrorFormatter CreateDefault()
public static ErrorFormatter CreateDefault(DotvvmConfiguration? config)
{
var f = new ErrorFormatter();
f.Formatters.Add((e, o) => DotvvmMarkupErrorSection.Create(e));
Expand Down Expand Up @@ -462,7 +463,7 @@ public static ErrorFormatter CreateDefault()
return null;
return new ExceptionAdditionalInfo(
"Control Hierarchy",
control.GetAllAncestors(includingThis: true).Select(c => c.DebugString(useHtml: true, multiline: false)).ToArray(),
control.GetAllAncestors(includingThis: true).Select(c => c.DebugString(config: config, useHtml: true, multiline: false)).ToArray(),
ExceptionAdditionalInfo.DisplayMode.ToHtmlListUnencoded
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Runtime/ErrorPageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ErrorPageTests

private static ErrorFormatter CreateFormatter()
{
var errorFormatter = ErrorFormatter.CreateDefault();
var errorFormatter = ErrorFormatter.CreateDefault(config);
return errorFormatter;
}

Expand Down

0 comments on commit 92e9ac9

Please sign in to comment.