Skip to content

Commit

Permalink
Resolve Error in CSharpLanguageService (#7519)
Browse files Browse the repository at this point in the history
* Resolve Error in CSharpLanguageService

* handle case where apiRevision codeFile is empty
  • Loading branch information
chidozieononiwu authored Jan 19, 2024
1 parent d2c5038 commit da7860b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/dotnet/APIView/APIViewWeb/Helpers/PageModelHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static async Task<ReviewContentModel> GetReviewContentAsync(
var activeRevision = await reviewRevisionsManager.GetLatestAPIRevisionsAsync(reviewId, apiRevisions, APIRevisionType.Automatic);
if (activeRevision == null)
{
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevison;
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonRedirectToIndexPage;
reviewPageContent.NotificationMessage = $"Review with ID {reviewId} has no valid APIRevisons";
return reviewPageContent;
}
Expand All @@ -271,7 +271,7 @@ public static async Task<ReviewContentModel> GetReviewContentAsync(
else
{
reviewPageContent.NotificationMessage = $"A revision with ID {revisionId} does not exist for review with id {reviewId}";
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevison;
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonRedirectToIndexPage;
return reviewPageContent;
}
}
Expand Down Expand Up @@ -308,14 +308,14 @@ public static async Task<ReviewContentModel> GetReviewContentAsync(
{
getCodeLines = true;
reviewPageContent.NotificationMessage = $"There is no diff between the two revisions. {activeRevision.Id} : {diffRevisionId}";
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevison;
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonProceedWithPageLoad;
}
}
else
{
getCodeLines = true;
reviewPageContent.NotificationMessage = $"A diffRevision with ID {diffRevisionId} does not exist for this review.";
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevison;
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonProceedWithPageLoad;
}
}

Expand All @@ -324,6 +324,13 @@ public static async Task<ReviewContentModel> GetReviewContentAsync(
codeLines = CreateLines(diagnostics: fileDiagnostics, lines: activeRevisionHtmlLines, comments: comments);
}

if (codeLines == null || codeLines.Length == 0)
{
reviewPageContent.NotificationMessage = $"A revision with ID {activeRevision.Id} has no content.";
reviewPageContent.Directive = ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonRedirectToIndexPage;
return reviewPageContent;
}

HashSet<string> preferredApprovers = new HashSet<string>();
var approverConfig = configuration["approvers"];
if (!string.IsNullOrEmpty(approverConfig))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public override Task<CodeFile> GetCodeFileAsync(string originalName, Stream stre
var nuspecEntry = archive.Entries.Single(entry => IsNuspec(entry.Name));

var dllEntries = archive.Entries.Where(entry => IsDll(entry.Name)).ToArray();
if (dllEntries.Length == 0)
{
return Task.FromResult(GetDummyReviewCodeFile(originalName, dependencies));
}

var dllEntry = dllEntries.First();
if (dllEntries.Length > 1)
Expand Down Expand Up @@ -96,7 +100,7 @@ public override Task<CodeFile> GetCodeFileAsync(string originalName, Stream stre
}

var assemblySymbol = CompilationFactory.GetCompilation(dllStream, docStream);
if ( assemblySymbol == null)
if (assemblySymbol == null)
{
return Task.FromResult(GetDummyReviewCodeFile(originalName, dependencies));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public enum ReviewContentModelDirective
{
ProceedWithPageLoad = 0,
TryGetlegacyReview,
ErrorDueToInvalidAPIRevison
ErrorDueToInvalidAPIRevisonProceedWithPageLoad,
ErrorDueToInvalidAPIRevisonRedirectToIndexPage

}

public class ReviewContentModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ public async Task<IActionResult> OnGetAsync(string id, string revisionId = null)
}
}

if (ReviewContent.Directive == ReviewContentModelDirective.ErrorDueToInvalidAPIRevison)
if (ReviewContent.Directive == ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonProceedWithPageLoad)
{
NotificationMessage = ReviewContent.NotificationMessage;
}

if (ReviewContent.Directive == ReviewContentModelDirective.ErrorDueToInvalidAPIRevisonRedirectToIndexPage)
{
return RedirectToPage("Index", new { notificationMessage = ReviewContent.NotificationMessage });
}

if (ReviewContent.APIRevisionsGrouped == null || !ReviewContent.APIRevisionsGrouped.Any())
{
return RedirectToPage("LegacyReview", new { id = id });
Expand Down

0 comments on commit da7860b

Please sign in to comment.