From d020652f50218210f8adf9791c29f817f7a94a83 Mon Sep 17 00:00:00 2001 From: Sanqui Date: Mon, 14 Dec 2020 17:48:11 +0100 Subject: [PATCH] [CLI] Display channel name for errors during ExportMultipleAsync (#452) --- .../Commands/Base/ExportMultipleCommandBase.cs | 8 ++++---- .../Exceptions/DiscordChatExporterException.cs | 4 ++-- DiscordChatExporter.Domain/Exporting/ChannelExporter.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportMultipleCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportMultipleCommandBase.cs index 7b28168a..4834b744 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportMultipleCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportMultipleCommandBase.cs @@ -32,7 +32,7 @@ namespace DiscordChatExporter.Cli.Commands.Base var operations = progress.Wrap().CreateOperations(channels.Count); var successfulExportCount = 0; - var errors = new ConcurrentBag(); + var errors = new ConcurrentBag<(Channel, string)>(); await channels.Zip(operations).ParallelForEachAsync(async tuple => { @@ -61,7 +61,7 @@ namespace DiscordChatExporter.Cli.Commands.Base } catch (DiscordChatExporterException ex) when (!ex.IsCritical) { - errors.Add(ex.Message); + errors.Add((channel, ex.Message)); } finally { @@ -71,8 +71,8 @@ namespace DiscordChatExporter.Cli.Commands.Base console.Output.WriteLine(); - foreach (var error in errors) - console.Error.WriteLine(error); + foreach (var (channel, error) in errors) + console.Error.WriteLine($"Channel '{channel}': {error}"); console.Output.WriteLine($"Successfully exported {successfulExportCount} channel(s)."); } diff --git a/DiscordChatExporter.Domain/Exceptions/DiscordChatExporterException.cs b/DiscordChatExporter.Domain/Exceptions/DiscordChatExporterException.cs index d1ee0823..84ed8634 100644 --- a/DiscordChatExporter.Domain/Exceptions/DiscordChatExporterException.cs +++ b/DiscordChatExporter.Domain/Exceptions/DiscordChatExporterException.cs @@ -46,9 +46,9 @@ Failed to perform an HTTP request. return new DiscordChatExporterException(message); } - internal static DiscordChatExporterException ChannelIsEmpty(string channel) + internal static DiscordChatExporterException ChannelIsEmpty() { - var message = $"Channel '{channel}' contains no messages for the specified period."; + var message = $"No messages for the specified period."; return new DiscordChatExporterException(message); } } diff --git a/DiscordChatExporter.Domain/Exporting/ChannelExporter.cs b/DiscordChatExporter.Domain/Exporting/ChannelExporter.cs index 9394fd19..64509b0b 100644 --- a/DiscordChatExporter.Domain/Exporting/ChannelExporter.cs +++ b/DiscordChatExporter.Domain/Exporting/ChannelExporter.cs @@ -59,7 +59,7 @@ namespace DiscordChatExporter.Domain.Exporting // Throw if no messages were exported if (!exportedAnything) - throw DiscordChatExporterException.ChannelIsEmpty(request.Channel.Name); + throw DiscordChatExporterException.ChannelIsEmpty(); } } } \ No newline at end of file