Skip to content

Commit

Permalink
Merge pull request #10 from devlead/feature/improve/exceptionlogging
Browse files Browse the repository at this point in the history
Improve exception logging & path escaping
  • Loading branch information
devlead authored Mar 25, 2024
2 parents a4b4e56 + 033d63b commit d9a74f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/ARI/Commands/InventoryCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cake.Common.IO;
using Microsoft.Identity.Client;
using System.Collections.Concurrent;

namespace ARI.Commands;
Expand Down Expand Up @@ -27,7 +28,11 @@ public override async Task<int> ExecuteAsync(CommandContext context, InventorySe
var modified = DateTimeOffset.UtcNow;
var markDownFileName = settings.MarkdownName + ".md";
var resourcesBag = new ConcurrentBag<(IResource Resource, DirectoryPath? Path)>();
settings.OutputPath = settings.OutputPath.MakeAbsolute(CakeContext.Environment);
if (settings.OutputPath.IsRelative)
{
Logger.LogInformation("Relative outputpath {outputpath} making absolute...", settings.OutputPath);
settings.OutputPath = settings.OutputPath.MakeAbsolute(CakeContext.Environment);
}
Logger.LogInformation("TenantId: {TenantId}", settings.TenantId);
Logger.LogInformation("OutputPath: {OutputPath}", settings.OutputPath);
Logger.LogInformation("Generate report in parallel: {GenerateInParallel}", settings.SkipTenantOverview);
Expand Down
4 changes: 3 additions & 1 deletion src/ARI/Extensions/StringMarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public static string Link(this string description, string? href = default)
: $"[{description}]({PathEscapeUriString(href ?? description)})";

public static string PathEscapeUriString(this string path)
=> path.Aggregate(
=> path
.TrimStart('/', '\\')
.Aggregate(
new StringBuilder(),
(sb, c) =>
!char.IsAsciiLetterOrDigit(c)
Expand Down
4 changes: 4 additions & 0 deletions src/ARI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
config.AddCommand<InventoryCommand>("inventory")
.WithDescription("Example inventory command.")
.WithExample(new[] { "inventory", "00000000-0000-0000-0000-000000000000", "outputpath" });

config.SetExceptionHandler(
ex => AnsiConsole.WriteException(ex, ExceptionFormats.ShowLinks)
);
});

return await app.RunAsync(args);

0 comments on commit d9a74f2

Please sign in to comment.