Changed to log error details in addition to file name

This commit is contained in:
Rob King
2015-06-04 21:01:35 +01:00
parent 67de77fe08
commit 8421b2f7e8
2 changed files with 10 additions and 22 deletions

View File

@@ -36,18 +36,15 @@ namespace Orchard.Recipes.Services {
var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes"); var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes");
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true); var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => {
{
var recipe = _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r));
if (recipe == null) try {
{ recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r)));
Logger.Error(new Exception(string.Format("Invalid recipe file: {0}", r)), "Invalid recipe file: {0}", r);
} }
else catch (Exception ex) {
{ Logger.Error(new Exception(string.Format("Invalid recipe file: {0}\nError: {1}", r, ex.Message)), "Invalid recipe file: {0}\nError: {1}", r, ex.Message);
recipes.Add(recipe);
} }
}); });
} }
else { else {

View File

@@ -20,21 +20,12 @@ namespace Orchard.Recipes.Services {
var recipe = new Recipe(); var recipe = new Recipe();
try { try {
if (string.IsNullOrEmpty(recipeText))
{ if (string.IsNullOrEmpty(recipeText)) {
return null; throw new Exception("Recipe is empty");
} }
XElement recipeTree; XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
try
{
recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
}
catch
{
return null;
}
var recipeSteps = new List<RecipeStep>(); var recipeSteps = new List<RecipeStep>();