augustjune/canoe

JSON Decoding Error

Closed this issue · 8 comments

Hey, thanks for creating this; I am playing around a little with canoe and encountered a bug: Whenever I poll for Updates with my bot (using Bot.polling[F].update), the application crashes with the following message/stack trace:

org.http4s.InvalidMessageBodyFailure: Invalid message body: Could not decode JSON: {
"ok" : true,
"result" : [
{
"update_id" : 112088157,
"message" : {
"message_id" : 479,
"from" : {
"id" : ,
"is_bot" : false,
"first_name" : "Jan",
"language_code" : "de"
},
"chat" : {
"id" : -357322183,
"title" : "Schnicktest1",
"type" : "group",
"all_members_are_administrators" : true
},
"date" : 1569522010,
"group_chat_created" : true
}
},
{
"update_id" : 112088158,
"message" : {
"message_id" : 480,
"from" : {
"id" : ,
"is_bot" : false,
"first_name" : "Jan",
"language_code" : "de"
},
"chat" : {
"id" : -357322183,
"title" : "Schnicktest1",
"type" : "group",
"all_members_are_administrators" : true
},
"date" : 1569522015,
"text" : "/schnick",
"entities" : [
{
"offset" : 0,
"length" : 8,
"type" : "bot_command"
}
]
}
},
{
"update_id" : 112088159,
"message" : {
"message_id" : 481,
"from" : {
"id" : ,
"is_bot" : false,
"first_name" : "Jan",
"language_code" : "de"
},
"chat" : {
"id" : -357322183,
"title" : "Schnicktest1",
"type" : "group",
"all_members_are_administrators" : true
},
"date" : 1569522021,
"text" : "/help",
"entities" : [
{
"offset" : 0,
"length" : 5,
"type" : "bot_command"
}
]
}
},
{
"update_id" : 112088160,
"message" : {
"message_id" : 482,
"from" : {
"id" : ,
"is_bot" : false,
"first_name" : "Jan",
"language_code" : "de"
},
"chat" : {
"id" : -357322183,
"title" : "Schnicktest1",
"type" : "group",
"all_members_are_administrators" : true
},
"date" : 1569522022,
"text" : "/blarn",
"entities" : [
{
"offset" : 0,
"length" : 6,
"type" : "bot_command"
}
]
}
}
]
}
at org.http4s.circe.CirceInstances$.$anonfun$defaultJsonDecodeError$1(CirceInstances.scala:189)
at org.http4s.circe.CirceInstances.$anonfun$jsonOfWithMedia$2(CirceInstances.scala:71)
at scala.util.Either.fold(Either.scala:192)
at org.http4s.circe.CirceInstances.$anonfun$jsonOfWithMedia$1(CirceInstances.scala:72)
at cats.data.EitherT.$anonfun$flatMap$1(EitherT.scala:100)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:139)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:376)
at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:316)
at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:136)
at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
at cats.effect.internals.IORunLoop$RestartCallback.run(IORunLoop.scala:366)
at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:70)
at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:36)
at cats.effect.internals.TrampolineEC$JVMTrampoline.super$startLoop(TrampolineEC.scala:93)
at cats.effect.internals.TrampolineEC$JVMTrampoline.$anonfun$startLoop$1(TrampolineEC.scala:93)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at cats.effect.internals.TrampolineEC$JVMTrampoline.startLoop(TrampolineEC.scala:93)
at cats.effect.internals.Trampoline.execute(Trampoline.scala:43)
at cats.effect.internals.TrampolineEC.execute(TrampolineEC.scala:44)
at cats.effect.internals.Callback$AsyncIdempotentCallback.apply(Callback.scala:137)
at cats.effect.internals.Callback$AsyncIdempotentCallback.apply(Callback.scala:124)
at org.http4s.client.blaze.Http1Connection.parsePrelude(Http1Connection.scala:296)
at org.http4s.client.blaze.Http1Connection.$anonfun$readAndParsePrelude$1(Http1Connection.scala:189)
at org.http4s.client.blaze.Http1Connection.$anonfun$readAndParsePrelude$1$adapted(Http1Connection.scala:188)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:447)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: DecodingFailure(Attempt to decode value on failed cursor, List(DownField(preCheckoutQuery), DownArray, DownField(result)))

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"`

(You might need to copy+paste the JSON into a formatter, sorry about that... And I removed the user ID of the messages, in the original JSON they are 8-digit numbers.)

These messages have not been handled/deleted yet and thus I cannot use my bot at all at the moment (with canoe) since they immediately come up when polling.

I guess there's something wrong with a Decoder which seems odd to me since (as far as I could tell) they are all auto/semiauto-derived, aren't they?

I cloned your repo and will try to find the problem / fix it and open a PR, but I wanted to let you know ASAP.

Hi, thank you for raising the issue. I'm going to check that right now

Renaming the field canoe.models.messages.SupergroupCreated.supergroupChatCreated to groupChatCreated seems to fix it. (Which makes sense, if you compare that case class to the first entry in the result-array of the JSON. Maybe the twitter API changed?

Don't know the terminology though, maybe there is a difference between "Group" and "SuperGroup"...?

You're close. In addition to SupergroupCreated there's also GroupChatCreated event, which I was missing. Receiving that kind of message from the Telegram was is not expected at the moment. Fixing that in #47

Ah, but that's no real solution. In the Telegram API documentation you can find both, group_chat_created and supergroup_chat_created . So I guess, you might need the SystemMessage GroupCreated as well? What I did for this event was to create a new Group in Telegram with the bot and a third user.

Cool :) Thanks a lot - I guess this can be closed then. So do you close this issue as repo owner? Don't know the proper etiquette here, I'm new to participating in open source software...

I'm going to make a new release, but anyway it's going to take some time before it's shipped to the maven repo.
Thank you again for addressing the issue. This project is on its early stage, so feel free to make a PR if you find something's missing or just would like to contribute :)
I will close the issue when the release is ready.

Okay, great! 👍

The issue is fixed in version 0.1.2 which is already available.