Fix: catch JsonException in list unwrap; improve export error message

Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/d2a03a38-0ed4-45c7-b8e7-615ffb35c971

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-04 11:28:04 +00:00 committed by GitHub
parent f8ab926074
commit 1835af12d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -57,7 +57,7 @@ public partial class ExportChannelsCommand : ExportCommandBase
{
throw new CommandException(
"No channel IDs provided. "
+ "Specify channel IDs as arguments or pipe them from a newline-separated list."
+ "Specify channel IDs as arguments or pipe them from the 'list channels' or 'list channels dm' commands."
);
}

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using CliFx;
using CliFx.Binding;
using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands.Base;
@ -30,11 +31,22 @@ public partial class UnwrapChannelsCommand : DiscordCommandBase
await foreach (var line in console.Input.ReadLinesAsync(cancellationToken))
sb.Append(line);
var channels =
JsonSerializer.Deserialize(
sb.ToString().Trim(),
CliJsonSerializerContext.Instance.ChannelArray
) ?? [];
Channel[] channels;
try
{
channels =
JsonSerializer.Deserialize(
sb.ToString().Trim(),
CliJsonSerializerContext.Instance.ChannelArray
) ?? [];
}
catch (JsonException)
{
throw new CommandException(
"Failed to parse input as a JSON channel array. "
+ "Pipe the output of 'list channels' or 'list channels dm' to this command."
);
}
var result = new List<Channel>();
var channelsByGuild = new Dictionary<Snowflake, IReadOnlyList<Channel>>();