Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError [ERR_ASSERTION]: protocol mismatch #9

Closed
iznaut opened this issue Oct 21, 2024 · 6 comments · Fixed by #15
Closed

AssertionError [ERR_ASSERTION]: protocol mismatch #9

iznaut opened this issue Oct 21, 2024 · 6 comments · Fixed by #15
Labels
bug Something isn't working

Comments

@iznaut
Copy link

iznaut commented Oct 21, 2024

➜  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
Copy link

Jay2645 commented Oct 22, 2024

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
Copy link
Owner

@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
Copy link

paceaux commented Oct 22, 2024

@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
Copy link
Owner

@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
Copy link

paceaux commented Oct 22, 2024

@marcomaroni-github Nice.

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

@iznaut
Copy link
Author

iznaut commented Oct 22, 2024

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

great work though!

@marcomaroni-github marcomaroni-github linked a pull request Oct 23, 2024 that will close this issue
@marcomaroni-github marcomaroni-github added the bug Something isn't working label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants