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

TypeError: Cannot read properties of undefined (reading '0') #4

Closed
madebyfabian opened this issue Feb 14, 2023 · 10 comments
Closed

TypeError: Cannot read properties of undefined (reading '0') #4

madebyfabian opened this issue Feb 14, 2023 · 10 comments

Comments

@madebyfabian
Copy link

Hey, awesome stuff! Trying to run the command, I get

/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/aicommits/bin/aicommits.js:98
        const aiCommit = json.choices[0].text;
                                     ^

TypeError: Cannot read properties of undefined (reading '0')
    at /Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/aicommits/bin/aicommits.js:98:38
    at Generator.next (<anonymous>)
    at fulfilled (/Users/fabian/.nvm/versions/node/v16.18.1/lib/node_modules/aicommits/bin/aicommits.js:6:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Using Node v16.18.1. Let me know which system details do you need

@Nutlope
Copy link
Owner

Nutlope commented Feb 14, 2023

Hey @madebyfabian, thanks for opening this issue! This error typically happens when you don't have the correct value for the OpenAI env variable. I recommend you do a printenv OPENAI_API_KEY to see what value you have it set to and verify that it matches an API key that's on your OpenAI API dashboard. The API key should have no whitespaces and should be in the shape of sk-xxxxxxxxxxxxxxx.

Could you verify you have the correct value for the env variable, open a brand new terminal, and try it out again?

@madebyfabian
Copy link
Author

@Nutlope Thanks for your quick answer? The printenv does return a value in this shape sk-xxxxxxxxxxxxxxxL0ku. the Dashboard also shows this key and tells me it was last used today.

@Nutlope
Copy link
Owner

Nutlope commented Feb 14, 2023

Hmm, weird. I have no idea what's going on unfortunately. I may try to add a debugging flag to the CLI soon that shows detailed console messages so folks can debug in situations like this.

In the meantime, can I ask what operating system you're using @madebyfabian?

@madebyfabian
Copy link
Author

@Nutlope Sure, using MacOS Ventura 13.0.1 (22A400).
Yeah maybe it would be great to catch that error before, so that when the key is not in a certain shape/undefined, it fails. Or maybe an API call to check if the key is valid.

@Nutlope
Copy link
Owner

Nutlope commented Feb 14, 2023

@madebyfabian Hmm that OS should definitely work. I agree that it'd be good to add better error handling for that, great idea.

Mind trying one more thing for me? I have a feeling it may be extra whitespace so could you do a unset OPENAI_API_KEY to remove the env var, go directly to your .zshrc by going to your root cd ~ then code .zshrc to open it up, and add export OPENAI_API_KEY="sk---" to the .zshrc somewhere.

After all of that, open up a fresh terminal and try it one more time. If it works, then it was whitespace and I should just trim extra whitespace.

@nelopuchades
Copy link

To give more context, the same thing happens to me in random situations. Sometimes it works and sometimes it doesn't. It should be related to Open AI response time or something like that. A better error handling and a flag to debug if something is not working would do the work imho.

image

@yusefren
Copy link
Contributor

yusefren commented Feb 14, 2023

I can confirm it is an Open AI issue

aicommits
▲ Welcome to AICommits!
▲ Generating your AI commit message...
{
  error: {
    message: 'The server had an error while processing your request. Sorry about that!',
    type: 'server_error',
    param: null,
    code: null
  }
}

@yusefren
Copy link
Contributor

@dilraj-vidyard
Copy link

Yeah, I am getting this too. I will report back this week if I am still having the issue.

Other info:

  • MacOS Version: 13.2 (22D49)
  • Node Version: v16.17.1

@privatenumber
Copy link
Collaborator

Duplicate of #5

The latest release should log the specific error from OpenAI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants