[CLI] Display channel name for errors during ExportMultipleAsync (#452)

This commit is contained in:
Sanqui 2020-12-14 17:48:11 +01:00 committed by GitHub
parent 63803f98aa
commit d020652f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View file

@ -32,7 +32,7 @@ namespace DiscordChatExporter.Cli.Commands.Base
var operations = progress.Wrap().CreateOperations(channels.Count); var operations = progress.Wrap().CreateOperations(channels.Count);
var successfulExportCount = 0; var successfulExportCount = 0;
var errors = new ConcurrentBag<string>(); var errors = new ConcurrentBag<(Channel, string)>();
await channels.Zip(operations).ParallelForEachAsync(async tuple => await channels.Zip(operations).ParallelForEachAsync(async tuple =>
{ {
@ -61,7 +61,7 @@ namespace DiscordChatExporter.Cli.Commands.Base
} }
catch (DiscordChatExporterException ex) when (!ex.IsCritical) catch (DiscordChatExporterException ex) when (!ex.IsCritical)
{ {
errors.Add(ex.Message); errors.Add((channel, ex.Message));
} }
finally finally
{ {
@ -71,8 +71,8 @@ namespace DiscordChatExporter.Cli.Commands.Base
console.Output.WriteLine(); console.Output.WriteLine();
foreach (var error in errors) foreach (var (channel, error) in errors)
console.Error.WriteLine(error); console.Error.WriteLine($"Channel '{channel}': {error}");
console.Output.WriteLine($"Successfully exported {successfulExportCount} channel(s)."); console.Output.WriteLine($"Successfully exported {successfulExportCount} channel(s).");
} }

View file

@ -46,9 +46,9 @@ Failed to perform an HTTP request.
return new DiscordChatExporterException(message); 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); return new DiscordChatExporterException(message);
} }
} }

View file

@ -59,7 +59,7 @@ namespace DiscordChatExporter.Domain.Exporting
// Throw if no messages were exported // Throw if no messages were exported
if (!exportedAnything) if (!exportedAnything)
throw DiscordChatExporterException.ChannelIsEmpty(request.Channel.Name); throw DiscordChatExporterException.ChannelIsEmpty();
} }
} }
} }