Skip to content

Commit

Permalink
Just report error if wrong number found
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Mar 31, 2020
1 parent 9f4f5cd commit 6a71ddd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions CodeConverter/Shared/ProjectConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ private ProjectConversion(IProjectContentsConverter projectContentsConverter, IE

var conversion = new ProjectConversion(projectContentsConverter, new[] { document }, Enumerable.Empty<TextDocument>(), languageConversion, cancellationToken, conversionOptions.ShowCompilationErrors, returnSelectedNode);
var conversionResults = await conversion.Convert(progress).ToArrayAsync();
var codeResult = conversionResults.SingleOrDefault(x => !string.IsNullOrWhiteSpace(x.ConvertedCode))
?? conversionResults.First();
return GetSingleResultForDocument(conversionResults, document, progress);
}

private static ConversionResult GetSingleResultForDocument(ConversionResult[] conversionResults, Document document, IProgress<ConversionProgress> progress)
{
var codeResults = conversionResults.Where(x => !string.IsNullOrWhiteSpace(x.ConvertedCode)).OrderByDescending(r => r.SourcePathOrNull == document.FilePath).ToArray();
if (codeResults.Count() != 1) {
progress.Report(new ConversionProgress($"ERROR: Expected one result, but received {codeResults.Count()}:{Environment.NewLine}{string.Join(Environment.NewLine, codeResults.Select(r => r.TargetPathOrNull))}"));
}
var codeResult = codeResults.First();
codeResult.Exceptions = conversionResults.SelectMany(x => x.Exceptions).ToArray();
return codeResult;
}
Expand Down

0 comments on commit 6a71ddd

Please sign in to comment.