Skip to content

Commit

Permalink
Add better error handling for the case when first PR analysis is run …
Browse files Browse the repository at this point in the history
…before the base branch analysis (#1559)
  • Loading branch information
costin-zaharia-sonarsource authored Apr 4, 2023
1 parent 64a0c4c commit 6fceba5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ public async Task DownloadCache_ThrowException()
var result = await sut.DownloadCache(localSettings);

result.Should().BeEmpty();
logger.AssertSingleDebugMessageExists("Incremental PR analysis: an error occurred while retrieving the cache entries! Found invalid data while decoding.");
logger.AssertSingleWarningExists("Incremental PR analysis: an error occurred while retrieving the cache entries! Found invalid data while decoding.");
logger.AssertNoErrorsLogged();
handler.VerifyAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,16 @@ public async Task DownloadCache_DeserializesMessage()
}

[TestMethod]
public async Task DownloadCache_WhenDownloadStreamReturnsNull_ReturnsEmptyAndLogsException()
public async Task DownloadCache_WhenDownloadStreamReturnsNull_ReturnsEmpty()
{
sut = new SonarQubeWebServer(MockIDownloader(null), version, logger, null);

var localSettings = CreateLocalSettings(ProjectKey, ProjectBranch);
var result = await sut.DownloadCache(localSettings);

result.Should().BeEmpty();
logger.AssertSingleWarningExists("Incremental PR analysis: an error occurred while retrieving the cache entries! Object reference not set to an instance of an object.");
logger.AssertNoWarningsLogged();
logger.AssertNoErrorsLogged(); // There are no errors or warnings logs but we will display an info message in the caller: "Cache data is empty. A full analysis will be performed."
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public override async Task<IList<SensorCacheEntry>> DownloadCache(ProcessedArgs
}
catch (Exception e)
{
logger.LogDebug(Resources.WARN_IncrementalPRCacheEntryRetrieval_Error, e.Message);
logger.LogWarning(Resources.WARN_IncrementalPRCacheEntryRetrieval_Error, e.Message);
logger.LogDebug(e.ToString());
return empty;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public override async Task<IList<SensorCacheEntry>> DownloadCache(ProcessedArgs
catch (Exception e)
{
logger.LogWarning(Resources.WARN_IncrementalPRCacheEntryRetrieval_Error, e.Message);
logger.LogDebug(e.ToString());
return empty;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ protected bool TryGetBaseBranch(ProcessedArgs localSettings, out string branch)

protected static IList<SensorCacheEntry> ParseCacheEntries(Stream dataStream)
{
if (dataStream == null)
{
return Array.Empty<SensorCacheEntry>();
}
var cacheEntries = new List<SensorCacheEntry>();
while (dataStream.Position < dataStream.Length)
{
Expand Down

0 comments on commit 6fceba5

Please sign in to comment.