Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CoDepend/Application/DependencyGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using CoDepend.Domain.Models;
using CoDepend.Domain.Models.Records;
using CoDepend.Domain.Utils;
using CoDepend.Infra;

namespace CoDepend.Application;

Expand Down Expand Up @@ -100,7 +101,7 @@ private async Task TryClassifyItem(
}
}
catch (OperationCanceledException) { throw; }
catch (Exception ex) { await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); }
catch (Exception ex) { Logger.LogError($"Error while processing '{item.Value}': {ex}"); }
}

private async Task<IEnumerable<(RelativePath Parent, RelativePath Item, IReadOnlyList<RelativePath> Deps)>> ParseAllAsync(
Expand Down Expand Up @@ -132,7 +133,7 @@ await Parallel.ForEachAsync(
catch (OperationCanceledException) { throw; }
catch (Exception ex)
{
await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}");
Logger.LogError($"Error while processing '{item.Value}': {ex}");
return null;
}
}
Expand Down
7 changes: 7 additions & 0 deletions CoDepend/Application/UpdateGraphUseCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CoDepend.Domain.Interfaces;
using CoDepend.Domain.Models.Enums;
using CoDepend.Domain.Models.Records;
using CoDepend.Infra;

namespace CoDepend.Application;

Expand All @@ -30,11 +31,17 @@ public async Task RunAsync(CancellationToken ct = default)
{
if (diff)
{
Logger.LogInformation("Running diff use case");

var compareGraph = await snapshotManager.GetLastSavedDependencyGraphAsync(snapshotOptions, ct) ?? throw new InvalidOperationException("Diff mode requires a saved snapshot, but none was found.");
await renderer.RenderDiffViewsAndSaveToFiles(graph, compareGraph, renderOptions, ct);
}
else
{
Logger.LogInformation("Running non-diff use case");

await renderer.RenderViewsAndSaveToFiles(graph, renderOptions, ct);
}
}

await snapshotManager.SaveGraphAsync(graph, snapshotOptions, ct);
Expand Down
14 changes: 13 additions & 1 deletion CoDepend/Domain/DependencyGraphSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using CoDepend.Domain.Models;
using CoDepend.Domain.Models.Records;
using CoDepend.Infra;
using MessagePack;
using MessagePack.Resolvers;

Expand Down Expand Up @@ -109,7 +110,18 @@ public static byte[] Serialize(ProjectDependencyGraph graph, int version = 1)
DependsOn = dependsOn,
};

return MessagePackSerializer.Serialize(dto, MsgPackOptions);
byte[] serializedResult = MessagePackSerializer.Serialize(dto, MsgPackOptions);

if (serializedResult.Length > 0)
{
Logger.LogInformation($"Size of serialized result: {serializedResult.Length}");
}
else
{
Logger.LogWarning($"The serialized result is empty");
}

return serializedResult;
}

public static ProjectDependencyGraph Deserialize(byte[] data, string projectRoot)
Expand Down
22 changes: 22 additions & 0 deletions CoDepend/Infra/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

using System;

namespace CoDepend.Infra;

public static class Logger
{
public static void LogInformation(string message)
{
Console.WriteLine($"INFO: {message}");
}

public static void LogWarning(string message)
{
Console.WriteLine($"WARN: {message}");
}

public static void LogError(string message)
{
Console.WriteLine($"ERROR: {message}");
}
}