Legato-Dev / Legato-NowPlaying

Let's share information of songs are playing on AIMP to SNS.
Other
11 stars 2 forks source link

An exception is not handled when Legato failed to post to Misskey (and Twitter?) #36

Open siketyan opened 6 years ago

siketyan commented 6 years ago

Summary

When AIMP was playing music, .NET Framework under Legato caught an exception below.

How to reproduce

I couldn't find how to reproduce the exception.

Screenshot

image

Stacktrace of the Exception

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Misq.Core.<Request>d__0.MoveNext()
---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Misq.Me.<Request>d__13.MoveNext()
---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LegatoNowPlaying.Services.Misskey.Service.<Post>d__7.MoveNext()
---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LegatoNowPlaying.Accounts.<Post>d__3.MoveNext()
---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LegatoNowPlaying.MainForm.<_PostAsync>d__19.MoveNext()
---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LegatoNowPlaying.MainForm.<<MainForm_Load>b__24_0>d.MoveNext()
---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
siketyan commented 6 years ago

I think it is a problem of server of Misskey, but I think Legato should add handling of this exception.

marihachi commented 6 years ago

どんなJSONを受け取った場合にどんな対策を取るべきかが分からないので、根本的な対策は難しそう 雑な対処の方法として、投稿時の例外は全部掴んでしまうというのがある

siketyan commented 6 years ago

そもそもJSONがきてない(サーバエラーしてる)んだけどステータスコード見てる?

marihachi commented 6 years ago

そもそも、それぞれのサービス(Twitter、Misskey)のHTTPレイヤーはそれぞれのライブラリによって隠蔽されているので、Legato-NowPlayingで関与すべきことではなさそう。 するとすれば、降ってきた例外を掴んでよしなにするくらいだと思う。

marihachi commented 6 years ago

https://github.com/CoreTweet/CoreTweet https://github.com/syuilo/Misq

marihachi commented 6 years ago

なんて例外が飛んできてる? Newtonsoft.Json.JsonReaderExceptionだけかな

siketyan commented 6 years ago

いまのところ確認できたのはそれぐらい CoreTweetがTwitterException投げる要領でMisqもMisskeyExceptionとか投げてくれるといいんだけどね、と思いつつ

marihachi commented 6 years ago

ふむ

Asteriskx commented 6 years ago

この間の DDoS 攻撃時に起きてたぽいから、 API 介して接続が出来ていないときに例外吐いてそうっていう予想はしてる。 例外は JsonReaderException だけ拾ってるけど、 Siketyan も言ってる通り、 各サービスごとに throw してあげるのもいいのかもしれない。