myConsciousness / atproto.dart

🦋 AT Protocol and Bluesky things for Dart and Flutter.
https://atprotodart.com
BSD 3-Clause "New" or "Revised" License
165 stars 15 forks source link

Bug Report: Trying to parse EmbedViewImages on a post that has EmbedViewExternal #282

Closed edisonlsm closed 1 year ago

edisonlsm commented 1 year ago

1. Current bug behavior

When trying to get a post with an embedded URL, the constructor is throwing the following error:

CheckedFromJsonException (CheckedFromJsonException
Could not create `_$_EmbedImages`.
There is a problem with "images".
type 'Null' is not a subtype of type 'List<dynamic>' in type cast)

Unfortunately, I could not dig deeper at the issue since I am not familiar with Freezed or the JSON Serialization method you are using, otherwise I would try to open a PR :(

But what I could get is that for some reason it's trying to create a EmbedViewImages and looking for an images array at the JSON even though the embed type is app.bsky.embed.external.

2. Expected behavior

I would expect the object to be parsed correctly.

3. Steps to reproduce

I first detected this bug when trying to load the timeline, but (fortunately) the issue is also reproducible when loading the thread for the specific post!

The following request should throw this same exception on parse:

bluesky.feeds.findPostThread(uri: AtUri.parse('at://did:plc:by3jhwdqgbtrcc7q4tkkv3cf/app.bsky.feed.post/3jtvi2jrijx2y'));

4. Flutter doctor output

flutter doctor -v
[!] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E261 darwin-arm64, locale
    pt-BR)
    • Flutter version 3.7.12 on channel stable at
      /Users/edisonlsm/fvm/versions/3.7.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (4 days ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

5. More environment information

atproto: 0.2.5 bluesky: 0.3.7

github-actions[bot] commented 1 year ago

Thanks for your contribution! :)

myConsciousness commented 1 year ago

Hi @edisonlsm !

Thanks for this issue :) When I tried it a few weeks ago, no error occurred, but maybe I didn't have enough test cases.

Also, as an aside, the embed field has the most challenging structure: it is a Union with 4 types. But, from reading your Issue, it doesn't seem to be that difficult a problem. I will check and fix it soon, thank you anyway! :)

myConsciousness commented 1 year ago

@edisonlsm

I understand why. I had missed that media in the hierarchy below embed is also Union.

I would fix it by making the media field type Union object :)

        "embed": {
          "$type": "app.bsky.embed.recordWithMedia",
          "media": {
            "$type": "app.bsky.embed.external",
            "external": {
              "uri": "https://bluesky-heatmap.fly.dev/",
              "thumb": {
                "$type": "blob",
                "ref": {
                  "$link": "bafkreig4g4l6fwfl6r5z7yydzzfo2l26k5pajgdq2ue2tdu3xszbd3y6p4"
                },
                "mimeType": "image/jpeg",
                "size": 267294
              },
              "title": "Bluesky Posts Heatmap Generator",
              "description": "Generates GitHub-style heatmaps from your Bluesky posts."
            }
          },
          "record": {
            "$type": "app.bsky.embed.record",
            "record": {
              "cid": "bafyreic26yhtn46jxaggts75mbzmxth3tab6k5wj6krbvrumj5t63jqnjq",
              "uri": "at://did:plc:by3jhwdqgbtrcc7q4tkkv3cf/app.bsky.feed.post/3jtoq4zmhvz2z"
            }
          }
        },
myConsciousness commented 1 year ago

@edisonlsm ,

I fixed this bug and it works now. I will release with some atproto features, I will prepare until tomorrow :)

edisonlsm commented 1 year ago

Oh, great to hear that @myConsciousness !!!

I hadn't dig deeper on the list embed structure until finding this bug, but now I see how complex it is 😰 Specially since we have 4 different embeds, each one with their own structure...

Good to have Bluesky growing the number of users and with that having more test cases 😅

myConsciousness commented 1 year ago

Hi @edisonlsm ,

If Dart supported Union as a language spec, this difficult process would not be necessary. The Dart team should have supported Union before I had to create this process lol

Anyway it's okay now, please just wait for release! :^)

myConsciousness commented 1 year ago

@edisonlsm ,

I released fix build! It's bluesky v0.3.8, please try it!

edisonlsm commented 1 year ago

Worked like a charm 😄