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
10 changes: 7 additions & 3 deletions CoDepend/Application/DependencyGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using CoDepend.Domain.Models;
using CoDepend.Domain.Models.Records;
using CoDepend.Domain.Utils;

using CoDepend.Infra.Logger;
namespace CoDepend.Application;

public sealed class DependencyGraphBuilder(IReadOnlyList<IDependencyParser> _dependencyParsers, BaseOptions _options)
Expand Down Expand Up @@ -100,7 +100,10 @@ private async Task TryClassifyItem(
}
}
catch (OperationCanceledException) { throw; }
catch (Exception ex) { await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); }
catch (Exception ex) {
//await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {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 +135,8 @@ await Parallel.ForEachAsync(
catch (OperationCanceledException) { throw; }
catch (Exception ex)
{
await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}");
//Task task = Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}");
Logger.LogError("Error while processing " + item.Value + ":" + ex?.ToString());
return null;
}
}
Expand Down
11 changes: 10 additions & 1 deletion CoDepend/Domain/DependencyGraphSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CoDepend.Domain.Models.Records;
using MessagePack;
using MessagePack.Resolvers;
using CoDepend.Infra.Logger;

namespace CoDepend.Domain;

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

return MessagePackSerializer.Serialize(dto, MsgPackOptions);
var result = MessagePackSerializer.Serialize(dto, MsgPackOptions);
if(result?.Length > 0) {
Logger.LogInformation(result.Length.ToString());
} else
{
Logger.LogWarning("Empty array returned");
}

return result ?? Array.Empty<byte>();;
}

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

#pragma warning disable CA1050 // Declare types in namespaces
public class Logger
#pragma warning restore CA1050 // Declare types in namespaces
{
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}");
}
}