Skip to content

Commit 1835af1

Browse files
CopilotTyrrrz
andauthored
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>
1 parent f8ab926 commit 1835af1

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override async ValueTask ExecuteAsync(IConsole console)
5757
{
5858
throw new CommandException(
5959
"No channel IDs provided. "
60-
+ "Specify channel IDs as arguments or pipe them from a newline-separated list."
60+
+ "Specify channel IDs as arguments or pipe them from the 'list channels' or 'list channels dm' commands."
6161
);
6262
}
6363

DiscordChatExporter.Cli/Commands/UnwrapChannelsCommand.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Text;
33
using System.Text.Json;
44
using System.Threading.Tasks;
5+
using CliFx;
56
using CliFx.Binding;
67
using CliFx.Infrastructure;
78
using DiscordChatExporter.Cli.Commands.Base;
@@ -30,11 +31,22 @@ public override async ValueTask ExecuteAsync(IConsole console)
3031
await foreach (var line in console.Input.ReadLinesAsync(cancellationToken))
3132
sb.Append(line);
3233

33-
var channels =
34-
JsonSerializer.Deserialize(
35-
sb.ToString().Trim(),
36-
CliJsonSerializerContext.Instance.ChannelArray
37-
) ?? [];
34+
Channel[] channels;
35+
try
36+
{
37+
channels =
38+
JsonSerializer.Deserialize(
39+
sb.ToString().Trim(),
40+
CliJsonSerializerContext.Instance.ChannelArray
41+
) ?? [];
42+
}
43+
catch (JsonException)
44+
{
45+
throw new CommandException(
46+
"Failed to parse input as a JSON channel array. "
47+
+ "Pipe the output of 'list channels' or 'list channels dm' to this command."
48+
);
49+
}
3850

3951
var result = new List<Channel>();
4052
var channelsByGuild = new Dictionary<Snowflake, IReadOnlyList<Channel>>();

0 commit comments

Comments
 (0)