tautologer / easy-bsky-bot-sdk

A typescript SDK for easily writing bots for https://bsky.app
GNU General Public License v3.0
36 stars 5 forks source link

Deleted posts mess with getPostParent #1

Open deepfates opened 1 year ago

deepfates commented 1 year ago

When climbing a thread, a deleted parent post will make the mention handler error out:

uncaught error in MENTION handler: TypeError: Cannot read properties of undefined (reading 'record')
    at mapBskyFeedPostToPost (.../dist/easy-bsky-bot-sdk.js:147:33)
    at mapThreadViewPostToPost (.../dist/easy-bsky-bot-sdk.js:183:12)
    at .../dist/easy-bsky-bot-sdk.js:214:22
    at Generator.next (<anonymous>)
    at fulfilled (...dist/easy-bsky-bot-sdk.js:10:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Solving this currently by wrapping in a try/catch but probably not ideal long term.

    let history: Post[] = [];
    try {
      history = await bot.getPostParents(post.uri);
    } catch (err) {
      console.error("Error getting post parents:", err);
      // just add the current post to the history
      history = [post];
    }