Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make debug views to be resilient to exceptions #28412

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions src/EFCore.Relational/Metadata/IRelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,41 +113,48 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder.Append(indentString).Append("RelationalModel: ");

if (Collation != null)
try
{
builder.AppendLine().Append(indentString).Append("Collation: ").Append(Collation);
builder.Append(indentString).Append("RelationalModel: ");

if (Collation != null)
{
builder.AppendLine().Append(indentString).Append("Collation: ").Append(Collation);
}

foreach (var table in Tables)
{
builder.AppendLine().Append(table.ToDebugString(options, indent + 2));
}

foreach (var view in Views)
{
builder.AppendLine().Append(view.ToDebugString(options, indent + 2));
}

foreach (var function in Functions)
{
builder.AppendLine().Append(function.ToDebugString(options, indent + 2));
}

foreach (var query in Queries)
{
builder.AppendLine().Append(query.ToDebugString(options, indent + 2));
}

foreach (var sequence in Sequences)
{
builder.AppendLine().Append(sequence.ToDebugString(options, indent + 2));
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(AnnotationsToDebugString(indent));
}
}

foreach (var table in Tables)
{
builder.AppendLine().Append(table.ToDebugString(options, indent + 2));
}

foreach (var view in Views)
{
builder.AppendLine().Append(view.ToDebugString(options, indent + 2));
}

foreach (var function in Functions)
{
builder.AppendLine().Append(function.ToDebugString(options, indent + 2));
}

foreach (var query in Queries)
{
builder.AppendLine().Append(query.ToDebugString(options, indent + 2));
}

foreach (var sequence in Sequences)
{
builder.AppendLine().Append(sequence.ToDebugString(options, indent + 2));
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
catch (Exception exception)
{
builder.Append(AnnotationsToDebugString(indent));
builder.AppendLine().AppendLine(CoreStrings.DebugViewError(exception.Message));
}

return builder.ToString();
Expand Down
69 changes: 38 additions & 31 deletions src/EFCore.Relational/Metadata/ISqlQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,59 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder
.Append(indentString)
.Append("SqlQuery: ");

if (Schema != null)
try
{
builder
.Append(Schema)
.Append('.');
}
.Append(indentString)
.Append("SqlQuery: ");

builder.Append(Name);

if ((options & MetadataDebugStringOptions.SingleLine) == 0)
{
if (Sql != null)
if (Schema != null)
{
builder.AppendLine().Append(indentString).Append(" Sql: ");
builder.AppendLine().Append(indentString).Append(new string(' ', 4)).Append(Sql);
builder
.Append(Schema)
.Append('.');
}

var mappings = EntityTypeMappings.ToList();
if (mappings.Count != 0)
builder.Append(Name);

if ((options & MetadataDebugStringOptions.SingleLine) == 0)
{
builder.AppendLine().Append(indentString).Append(" EntityTypeMappings: ");
foreach (var mapping in mappings)
if (Sql != null)
{
builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
builder.AppendLine().Append(indentString).Append(" Sql: ");
builder.AppendLine().Append(indentString).Append(new string(' ', 4)).Append(Sql);
}
}

var columns = Columns.ToList();
if (columns.Count != 0)
{
builder.AppendLine().Append(indentString).Append(" Columns: ");
foreach (var column in columns)
var mappings = EntityTypeMappings.ToList();
if (mappings.Count != 0)
{
builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
builder.AppendLine().Append(indentString).Append(" EntityTypeMappings: ");
foreach (var mapping in mappings)
{
builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
}
}
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(AnnotationsToDebugString(indent + 2));
var columns = Columns.ToList();
if (columns.Count != 0)
{
builder.AppendLine().Append(indentString).Append(" Columns: ");
foreach (var column in columns)
{
builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
}
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(AnnotationsToDebugString(indent + 2));
}
}
}
catch (Exception exception)
{
builder.AppendLine().AppendLine(CoreStrings.DebugViewError(exception.Message));
}

return builder.ToString();
}
Expand Down
103 changes: 55 additions & 48 deletions src/EFCore.Relational/Metadata/IStoreFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,72 +71,79 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder
.Append(indentString)
.Append("StoreFunction: ");

if (ReturnType != null)
{
builder.Append(ReturnType);
}
else
try
{
builder.Append(EntityTypeMappings.FirstOrDefault()?.EntityType.DisplayName() ?? "");
}
builder
.Append(indentString)
.Append("StoreFunction: ");

builder.Append(' ');
if (ReturnType != null)
{
builder.Append(ReturnType);
}
else
{
builder.Append(EntityTypeMappings.FirstOrDefault()?.EntityType.DisplayName() ?? "");
}

if (Schema != null)
{
builder
.Append(Schema)
.Append('.');
}
builder.Append(' ');

builder.Append(Name);
if (Schema != null)
{
builder
.Append(Schema)
.Append('.');
}

if (IsBuiltIn)
{
builder.Append(" IsBuiltIn");
}
builder.Append(Name);

if ((options & MetadataDebugStringOptions.SingleLine) == 0)
{
var parameters = Parameters.ToList();
if (parameters.Count != 0)
if (IsBuiltIn)
{
builder.AppendLine().Append(indentString).Append(" Parameters: ");
foreach (var parameter in parameters)
{
builder.AppendLine().Append(parameter.ToDebugString(options, indent + 4));
}
builder.Append(" IsBuiltIn");
}

var mappings = EntityTypeMappings.ToList();
if (mappings.Count != 0)
if ((options & MetadataDebugStringOptions.SingleLine) == 0)
{
builder.AppendLine().Append(indentString).Append(" EntityTypeMappings: ");
foreach (var mapping in mappings)
var parameters = Parameters.ToList();
if (parameters.Count != 0)
{
builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
builder.AppendLine().Append(indentString).Append(" Parameters: ");
foreach (var parameter in parameters)
{
builder.AppendLine().Append(parameter.ToDebugString(options, indent + 4));
}
}
}

var columns = Columns.ToList();
if (columns.Count != 0)
{
builder.AppendLine().Append(indentString).Append(" Columns: ");
foreach (var column in columns)
var mappings = EntityTypeMappings.ToList();
if (mappings.Count != 0)
{
builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
builder.AppendLine().Append(indentString).Append(" EntityTypeMappings: ");
foreach (var mapping in mappings)
{
builder.AppendLine().Append(mapping.ToDebugString(options, indent + 4));
}
}
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(AnnotationsToDebugString(indent: indent + 2));
var columns = Columns.ToList();
if (columns.Count != 0)
{
builder.AppendLine().Append(indentString).Append(" Columns: ");
foreach (var column in columns)
{
builder.AppendLine().Append(column.ToDebugString(options, indent + 4));
}
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(AnnotationsToDebugString(indent: indent + 2));
}
}
}
catch (Exception exception)
{
builder.AppendLine().AppendLine(CoreStrings.DebugViewError(exception.Message));
}

return builder.ToString();
}
Expand Down
Loading