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

Format validation error. #65

Merged
merged 2 commits into from
Sep 17, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private bool IsValid(TemplateContainer rootContainer, ICollection<TemplateError>
{
if (!rootContainer.MatchTemplateName(TargetTemplateTypeName))
{
errors.Add(new TemplateError($"Expected {nameof(rootContainer.TemplateType)} value {TargetTemplateTypeName}, actual {rootContainer.TemplateType}."));
errors.Add(new TemplateError($"Expected {nameof(rootContainer.TemplateType)} value {TargetTemplateTypeName}, actual {rootContainer.TemplateType ?? "Not Found"}."));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ public static bool IsValid(this IValidatableObject input, out string error)
return true;
}

builder.Append("Validation errors: ");
foreach (var validationError in validationErrors)
{
builder.AppendLine($"{validationError.ErrorMessage}");
}

builder.AppendLine("Validation errors:");
builder.Append(string.Join("\n", validationErrors.Select(e => e.ErrorMessage)));
error = builder.ToString();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ public static T ToValidTemplate<T>(this JToken token)

if (errors.Any())
{
string errorMessage = string.Join(", \n", errors.Select(e => e.Message));
throw new InvalidTemplateException($"Failed to deserialize the template content: {errorMessage}");
string errorMessage = string.Join(string.Empty, errors.Select(e => FormatErrorMessage(e.Message)));
throw new InvalidTemplateException($"Failed to deserialize the {typeof(T).Name} content: {errorMessage}");
}

return obj;
}

private static string FormatErrorMessage(string errMessage)
{
// Remove the path information if it was empty.
errMessage = errMessage.Replace("Path ''.", string.Empty);
errMessage = "\n " + errMessage;
return errMessage;
}
}
}