Blazor: Add element/component name for duplicate key (#24153)
* Add element/component name for duplicate key * Add in keyword for frame param Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com> Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com>
This commit is contained in:
parent
113805aba8
commit
0ef891f75e
|
|
@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
|
|||
{
|
||||
if (result.ContainsKey(key))
|
||||
{
|
||||
ThrowExceptionForDuplicateKey(key);
|
||||
ThrowExceptionForDuplicateKey(key, frame);
|
||||
}
|
||||
|
||||
result[key] = new KeyedItemInfo(oldStartIndex, -1);
|
||||
|
|
@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
|
|||
{
|
||||
if (existingEntry.NewIndex >= 0)
|
||||
{
|
||||
ThrowExceptionForDuplicateKey(key);
|
||||
ThrowExceptionForDuplicateKey(key, frame);
|
||||
}
|
||||
|
||||
result[key] = new KeyedItemInfo(existingEntry.OldIndex, newStartIndex);
|
||||
|
|
@ -355,9 +355,19 @@ namespace Microsoft.AspNetCore.Components.RenderTree
|
|||
return result;
|
||||
}
|
||||
|
||||
private static void ThrowExceptionForDuplicateKey(object key)
|
||||
private static void ThrowExceptionForDuplicateKey(object key, in RenderTreeFrame frame)
|
||||
{
|
||||
throw new InvalidOperationException($"More than one sibling has the same key value, '{key}'. Key values must be unique.");
|
||||
switch (frame.FrameType)
|
||||
{
|
||||
case RenderTreeFrameType.Component:
|
||||
throw new InvalidOperationException($"More than one sibling of component '{frame.ComponentType}' has the same key value, '{key}'. Key values must be unique.");
|
||||
|
||||
case RenderTreeFrameType.Element:
|
||||
throw new InvalidOperationException($"More than one sibling of element '{frame.ElementName}' has the same key value, '{key}'. Key values must be unique.");
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"More than one sibling has the same key value, '{key}'. Key values must be unique.");
|
||||
}
|
||||
}
|
||||
|
||||
private static object KeyValue(ref RenderTreeFrame frame)
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
|
||||
// Act/Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => GetSingleUpdatedComponent());
|
||||
Assert.Equal("More than one sibling has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
Assert.Equal("More than one sibling of element 'el' has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -357,7 +357,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
|
||||
// Act/Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => GetSingleUpdatedComponent());
|
||||
Assert.Equal("More than one sibling has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
Assert.Equal("More than one sibling of element 'el' has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -374,7 +374,7 @@ namespace Microsoft.AspNetCore.Components.Test
|
|||
|
||||
// Act/Assert
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => GetSingleUpdatedComponent());
|
||||
Assert.Equal("More than one sibling has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
Assert.Equal("More than one sibling of element 'el' has the same key value, 'key1'. Key values must be unique.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue