Skip to content

Commit

Permalink
fix: Null Annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Jul 19, 2023
1 parent f96bb25 commit f793d78
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ private SnapshotGenerator()

/// <summary>returns a success</summary>
public GenerateResult GenerateProject(BuildPartition buildPartition, ILogger logger, string rootArtifactsFolderPath)
=> GenerateResult.Success(null, Array.Empty<string>());
=> GenerateResult.Success(ArtifactsPaths.Empty, Array.Empty<string>());
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
using System;
using System.Security.Cryptography;
using JsonSerializer = SimpleJson.SimpleJson;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Toolchains.Snapshot.Stores
{
internal static class HashUtility
{

public static string ToHash<T>(this T source)
public static string ToHash<T>([NotNull] this T source)
{

try
{

using var memory = new System.IO.MemoryStream(4000);
using var streamWriter = new System.IO.StreamWriter(memory, System.Text.Encoding.UTF8);
JsonSerializer.SerializeObject(streamWriter, source);
JsonSerializer.SerializeObject(streamWriter, source!);
memory.Position = 0;
using var hashCalulator = SHA256.Create();
var bytes = hashCalulator.ComputeHash(memory);
return Convert.ToBase64String(bytes);

throw new Exception("Can not serialize");
var result = Convert.ToBase64String(bytes);
return result;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,22 @@ void ISnapshotStore.Export(Summary summary, ILogger logger)

void ISnapshotStore.ExportEnd(ILogger logger)
{
var filePath = string.Empty;
try
if (storeInfo is not null)
{
filePath = Path.Combine(artifactsPath ?? string.Empty, Filename);
File.WriteAllText(filePath, JsonConvert.SerializeObject(storeInfo));
var filePath = string.Empty;
try
{
filePath = Path.Combine(artifactsPath ?? string.Empty, Filename);
File.WriteAllText(filePath, JsonConvert.SerializeObject(storeInfo));
}
catch (Exception)
{
logger.WriteError($"{nameof(JsonSnapshotStore)} error in generating the file {filePath}");
}
}
catch (Exception)
else
{
logger.WriteError($"{nameof(JsonSnapshotStore)} error in generating the file {filePath}");
logger.WriteError($"{nameof(JsonSnapshotStore)} error invali call sequence");
}
}

Expand All @@ -143,9 +150,15 @@ void ISnapshotStore.ExportEnd(ILogger logger)
if (storeInfo?.Benchmarks?.FirstOrDefault(b => b.Id == id) is BenchmarkStoreInfo benchmarkResult)
{
var ai = benchmarkResult.ExecuteResults?.FirstOrDefault(e => e.LunchIndex == executeParameters.LaunchIndex);
if (ai is { })
if (ai is not null)
{
return new ExecuteResult(ai.FoundExecutable, ai.ExitCode, default, ai.Results, ai.PrefixedLines, ai.StandardOutput, ai.LunchIndex);
return new ExecuteResult(ai.FoundExecutable,
ai.ExitCode,
default,
ai.Results ?? Array.Empty<string>(),
ai.PrefixedLines ?? Array.Empty<string>(),
ai.PrefixedLines ?? Array.Empty<string>(),
ai.LunchIndex);
}
}
executeParameters.Logger.WriteError($"Cannot find Snapshot for BenchmarkCase {executeParameters.BenchmarkId}");
Expand Down

0 comments on commit f793d78

Please sign in to comment.