Don't fully trust AI in dev work! /yet
Tags: javascript, node, github, twitter
Published: 2022-01-18 08:23:21

# Let's talk about AI tools for code completion.

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'. 

----------------------------------------

# What was the 'bug' anyway?

I was making a Twitter bot in NodeJS. Get some data from Reddit, and post it on  [Twitter bot](https://twitter.com/RedditTweetz) 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. 

----------------------------------------

# Constructing the constructor

First one, it's okay. TAB.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642400736357/x9xhGS1iUb.png)

Seems good, TAB!

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642400773111/kPQHXnHx7.png)

Awesome. GitHub Copilot is great!

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642400815563/fFwz-PuT1.png)

It's so easy. TAB and there we go. Constructor finished!

----------------------------------------

# Testing

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.

----------------------------------------

# Debugging

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.

----------------------------------------

# 'Aha!' Moment

Maybe... It's the wrong naming of the constructor fields. So I check. Now I rely on IntelliSense and typing fields.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642401881882/Dk5yMtkJo.png)

Seems good.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642401939354/0o3oStm1Z.png)

Keep on.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642401981264/To5OPqFqD.png)

Okay. Onto the last one.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642402040610/lQOJXguzl.png)

Wait, what? Wasn't it *accessToken..*? My literal reaction was: **NO WAY! Are you kidding me?!** 😂

----------------------------------------

GitHub Copilot: 

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642400815563/fFwz-PuT1.png)

IntelliSense: 

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1642402040610/lQOJXguzl.png)

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 me to use the **accessTokenSecret** field for a constructor, but the problem was that there isn’t a field with such a name!

The right one was **accessSecret**, recommended by IntelliSense engine.

----------------------------------------

# There is always an opportunity to learn

So yeah… There are zero places that can teach you those things. You must experience them and unlock that kind of knowledge. 😄

----------------------------------------

# Keep going!

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***