Skip to content

Commit

Permalink
Fixed to handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
noriokun4649 committed Aug 8, 2024
1 parent 3d5ac20 commit a091a05
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public IEnumerable<Chat> GetChats(ChannelInfo channel, DateTime time)
else
throw new ChatCollectException($"コメント取得でエラーが発生: {e}", chatCollectTask.Exception);
}
if (chatSessionTask?.IsFaulted ?? false)
{
//非同期部分で例外発生
var e = chatSessionTask.Exception.InnerExceptions.Count == 1
? chatSessionTask.Exception.InnerExceptions[0] : chatSessionTask.Exception;
// 有志のコミュニティチャンネルで生放送がされてない場合にエラー扱いされると使いづらいので
if (e is LiveNotFoundException)
notOnAir = true;
else
throw new ChatCollectException($"コメント取得でエラーが発生: {e}", chatSessionTask.Exception);
}

var liveId = liveIdResolver.Resolve(channel.NetworkId, channel.ServiceId).ToString();

Expand Down Expand Up @@ -143,6 +154,7 @@ private async Task CollectChat(CancellationToken cancellationToken)
{
try
{
await Task.Delay(2500, cancellationToken).ConfigureAwait(false);
//コメント投稿(視聴)セッションのRoomメッセージでPostKeyを取得出来るまでロックして待機
messageServers.TryTake(out var message, Timeout.Infinite);

Expand Down Expand Up @@ -205,7 +217,7 @@ public void Dispose()
}
//Waitからの例外がタスクがキャンセルされたことによるものか、通信エラー等なら無視
catch (AggregateException e) when (e.InnerExceptions.All(
innerE => innerE is OperationCanceledException || innerE is ChatReceivingException || innerE is NetworkNicoLiveCommentReceiverException
innerE => innerE is OperationCanceledException || innerE is ChatReceivingException || innerE is NetworkNicoLiveCommentReceiverException || innerE is NicoLiveCommentSenderException
))
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public IEnumerable<Chat> GetChats(ChannelInfo channel, DateTime time)
? chatCollectTask.Exception.InnerExceptions[0] : chatCollectTask.Exception;
throw new ChatCollectException($"コメント取得でエラーが発生: {e}", chatCollectTask.Exception);
}
if (chatSessionTask?.IsFaulted ?? false)
{
//非同期部分で例外発生
var e = chatSessionTask.Exception.InnerExceptions.Count == 1
? chatSessionTask.Exception.InnerExceptions[0] : chatSessionTask.Exception;
throw new ChatCollectException($"コメント取得でエラーが発生: {e}", chatSessionTask.Exception);
}

var ret = new List<Chat>();
while (commentTagQueue.TryDequeue(out var tag))
Expand Down Expand Up @@ -176,7 +183,8 @@ public void Dispose()
}
//Waitからの例外がタスクがキャンセルされたことによるものか、通信エラー等なら無視
catch (AggregateException e) when (e.InnerExceptions.All(
innerE => innerE is OperationCanceledException || innerE is ChatReceivingException || innerE is NetworkNicoLiveCommentReceiverException
innerE => innerE is OperationCanceledException || innerE is ChatReceivingException ||
innerE is NetworkNicoLiveCommentReceiverException || innerE is NicoLiveCommentSenderException
))
{
}
Expand Down

0 comments on commit a091a05

Please sign in to comment.