marcomaroni-github / twitter-to-bluesky

Import all tweets exported from X/Twitter to a Bluesky account.
Other
139 stars 6 forks source link

AssertionError [ERR_ASSERTION]: protocol mismatch #9

Closed iznaut closed 4 days ago

iznaut commented 5 days ago
➜  twitter-to-bluesky git:(main) ✗ npm run start_log

> twittertobluesky@0.3.1 start_log
> npx tsc && node app.js > import.log

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^

AssertionError [ERR_ASSERTION]: protocol mismatch
    at Object.request (/Users/izzy/Repos/twitter-to-bluesky/node_modules/follow-redirects/index.js:530:14)
    at Object.get (/Users/izzy/Repos/twitter-to-bluesky/node_modules/follow-redirects/index.js:537:44)
    at /Users/izzy/Repos/twitter-to-bluesky/app.js:51:34
    at new Promise (<anonymous>)
    at resolveShorURL (/Users/izzy/Repos/twitter-to-bluesky/app.js:50:12)
    at cleanTweetText (/Users/izzy/Repos/twitter-to-bluesky/app.js:69:34)
    at main (/Users/izzy/Repos/twitter-to-bluesky/app.js:184:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: 'http:',
  expected: 'https:',
  operator: '=='
}

Node.js v20.18.0

Based on what I can tell from the log, it looks like it's failing on this tweet since it's the last one (and doesn't get posted to Bluesky:

Parse tweet id '951857441'
 Created at 2008-10-08T21:17:00.000Z
 Full text 'Dtoiders! Come join the pictoblog fun! Draw pictures on your DS and share them with your fellow Dtoiders: http://tinyurl.com/3k9dm2'
Jay2645 commented 5 days ago

I am seeing the same thing:


> twittertobluesky@0.3.1 start_log
> npx tsc && node app.js > import.log

node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

AssertionError [ERR_ASSERTION]: protocol mismatch
    at Object.request (/home/jay/Bluesky/node_modules/follow-redirects/index.js:530:14)
    at Object.get (/home/jay/Bluesky/node_modules/follow-redirects/index.js:537:44)
    at /home/jay/Bluesky/app.js:51:34
    at new Promise (<anonymous>)
    at resolveShorURL (/home/jay/Bluesky/app.js:50:12)
    at cleanTweetText (/home/jay/Bluesky/app.js:69:34)
    at main (/home/jay/Bluesky/app.js:233:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: 'http:',
  expected: 'https:',
  operator: '=='
}

Node.js v22.10.0
SIMULATE is OFF
Parse tweet id '652973377452306432'
 Created at 2015-10-10T22:25:59.000Z
 Full text 'Made a Twitter! Let's hope I actually remember to use it this time. #myfirstTweet'
Bluesky post create, URL: https://bsky.app/profile/englishmobster.bsky.social/post/3l72xqdt3bm2x
Parse tweet id '652974931467091968'
 Created at 2015-10-10T22:32:10.000Z
 Full text 'A bunch of screenshots from "Tusks and Tigerskins", the game I'm working on: http://t.co/BadSkgikFD #screenshotsaturday'

I think the issue is the shortened link - it's http://, not https://. Doing a find and replace http -> https in data/tweets.js helped a bit, but I still failed out a little later with a different error:


> twittertobluesky@0.3.1 start_log
> npx tsc && node app.js > import.log

Error parsing url https://t.co/cEVbnUq94r
Error parsing url https://t.co/37jqou8xnR
Error parsing url https://t.co/mgyocrvVmc
Error parsing url https://t.co/ffqO50oVYO
Error parsing url https://t.co/hsy0yvex34
Error parsing url https://t.co/37jqou8xnR
/home/jay/Bluesky/node_modules/@atproto/xrpc/dist/xrpc-client.js:75
                throw new types_1.XRPCError(resCode, error, message, resHeaders);
                      ^

XRPCError: This file is too large. It is 1.31MB but the maximum size is 976.56KB.
    at AtpAgent.call (/home/jay/Bluesky/node_modules/@atproto/xrpc/dist/xrpc-client.js:75:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async PostRecord.create (/home/jay/Bluesky/node_modules/@atproto/api/dist/client/index.js:1282:21)
    at async main (/home/jay/Bluesky/app.js:264:36) {
  error: 'BlobTooLarge',
  headers: {
    'access-control-allow-origin': '*',
    'cache-control': 'private',
    'content-length': '107',
    'content-type': 'application/json; charset=utf-8',
    date: 'Tue, 22 Oct 2024 02:28:14 GMT',
    etag: 'W/"6b-XCfHuE8hl1kyJbs0m3Osfof07Pg"',
    'keep-alive': 'timeout=90',
    'ratelimit-limit': '5000',
    'ratelimit-policy': '5000;w=3600',
    'ratelimit-remaining': '4972',
    'ratelimit-reset': '1729567277',
    'strict-transport-security': 'max-age=63072000',
    vary: 'Authorization, Accept-Encoding',
    'x-powered-by': 'Express'
  },
  success: false,
  status: 400
}
marcomaroni-github commented 5 days ago

@Jay2645 they should be two different problems, for the http url resolution problem I made a branch with a possible fix https://github.com/marcomaroni-github/twitter-to-bluesky/tree/9-assertion-protocol-mismatch, @Jay2645 @iznaut try it and tell me if it solves the "protocol mismatch" problem

paceaux commented 4 days ago

@marcomaroni-github I was going to submit a PR, but I see that you're already working on it.

I resolved this in the resolveShorURL function by checking if the URL was http / s and then using the appropriate url:

I first imported both http and https at the top:

import { https, http } from 'follow-redirects';
async function resolveShorURL(url: string): Promise<string> {
    const isHttp = url.startsWith("http://");
    return new Promise<string>((resolve, reject) => {
        if (isHttp) {
            http.get(url, response => {
                resolve(response.responseUrl);
            }).on('error', err => {
                console.warn(`Error parsing url ${url}`);
                resolve(url);
            });
        } else {
            https.get(url, response => {
                resolve(response.responseUrl);
            }).on('error', err => {
                console.warn(`Error parsing url ${url}`);
                resolve(url);
            });
        }
    });
}
marcomaroni-github commented 4 days ago

@paceaux yes, your solution is very similar to mine, you can check it into the branch https://github.com/marcomaroni-github/twitter-to-bluesky/tree/9-assertion-protocol-mismatch

paceaux commented 4 days ago

@marcomaroni-github Nice.

Not that my opinion matters but... ¿approved?

iznaut commented 4 days ago

branch worked for a while, but died on a different issue (see #11 )

great work though!