After spending quite a bit of time debugging my code, what's wrong with it, I've found the 'bug'. Not the ordinary one.
Don't fully rely on AI. Seems simple right? However, when you are doing some easy/repetitive stuff, you might fall under influence of just 'tabbing'.
I was making a Twitter bot in NodeJS. Get some data from Reddit, and post it on Twitter bot account.
First off, I need a library, to simplify things about auth and whatever. A'ight, done.
npm install, make file structure, git init.
Here comes the fun part. I'm writing a constructor for a Twitter client. It needs 4 elements:
API key
API secret
Access token
Access secret
Okay, fair enough.
First one, it's okay. TAB.
Seems good, TAB!
Awesome. GitHub Copilot is great!
It's so easy. TAB and there we go. Constructor finished!
Let's try to get a simple 'Hello World!' tweet out there.
401, Unauthorized.
Umm, what? Let's go to the .env file, let's check if the naming is correct. Copy, paste.
Check.
401, Unauthorized.
Okay, let's check for Twitter stuff. Check permissions, regenerate keys.
Check.
401, Unauthorized.
Now comes the part where I tried to debug code, try a different library that supports Twitter's V2 API. No success.
Google, google, google. Try this, try that. Progress: NULL
I go for a walk, hoping for an 'Aha!' moment.
No luck. Back to work! Open Postman. Input parameters. Check headers, check body.
Send.
It worked!
Hmm, what could it be? Open postman, copy the curl request. Paste it in Notepad++.
I previously turned on debug mode in my code, copied the curl request from there too. Paste it in Notepad++.
Double-click one. Check.
Double-click another one. Check.
Another one. Check.
...
One is missing. How's that possible??
Now I went to the library docs.
Do you know what I did? Doesn't make sense, but let's try. Better than nothing.
Search for a method to input custom headers.
Nope. I did google (a lot) previously, about errors, and whatnot, but either there was no answer, or it was a typo in the .env file.
Maybe... It's the wrong naming of the constructor fields. So I check. Now I rely on IntelliSense and typing fields.
Seems good.
Keep on.
Okay. Onto the last one.
Wait, what? Wasn't it accessToken..? My literal reaction was: NO WAY! Are you kidding me?! 😂
GitHub Copilot:
IntelliSense:
GitHub Copilot’s AI was trained on the publicly available codebase. So, you have to take care of bugs others have written in their code!
GHC recommended I use the
The right one was
So yeah… There are zero places that can teach you those things. You must experience them and unlock that kind of knowledge. 😄
These are my .02 cents. Don't let code completion AI tools rule your work. I'm sure there is a lot of funny stories like this. But we all make mistakes. Embrace them as learning opportunities.
I don't blame GHC for this. I blame myself. But whatever. At least I got some experience. There is always space for improvement.
Fun one for sure.
Thank you for reading!
_ktb
First Published here