google-translate-api icon indicating copy to clipboard operation
google-translate-api copied to clipboard

Unhandled Promise Rejection. Error.captureStackTrace

Open Kefir101 opened this issue 1 year ago • 11 comments

I had to come back to this specific API because now I need the language found as well. Removing the api call makes the code works fine, so it has to be here.

Running for react-native and expo app on windows, all I'm doing is a simple call using the documentation (in an async function). React native 69.9, expo sdk 46, react 18. Not sure what else to put. image

Kefir101 avatar Jun 23 '23 14:06 Kefir101

Could you share minimal reproducible code of your app?

vitalets avatar Jun 23 '23 15:06 vitalets

I'll try that, but it will take a while to get the minimal amount. At least a few days.

Kefir101 avatar Jun 24 '23 01:06 Kefir101

I'm still working on it, but what I noticed is after starting the expo server after a while again the translate worked twice and then it gives the stacktrace error every time after, so I think it has something to do with caching in your code.

Kefir101 avatar Jul 02 '23 02:07 Kefir101

@vitalets https://github.com/Kefir101/Shortened-VeganChecker

Kefir101 avatar Jul 02 '23 04:07 Kefir101

@Kefir101 Is this error appears on app launch or after making actual call to translate()? And could you try to check and log text value before translation (I assume empty text can trigger an error)?

async function parseTextBothWays(text) {
  if (text) {
    console.log(text);
    let translated = await translate(text, { to: 'en' });
  }
}

And just as experiment, could you replace translate() call with explicitly triggered error and share the results, like:

async function parseTextBothWays(text) {
  if (text) {
    console.log(text);
    // let translated = await translate(text, { to: 'en' });
   throw new Error('my error');
  }
}

vitalets avatar Jul 02 '23 08:07 vitalets

@vitalets Error only appears when making the translate() call, but I noticed it now took 5-10 pictures to start giving the error, I think it has something to do with how much text has been translated already. Translating "" (empty) still gives the error, and replacing the translate() with throwing 'my error' leads to only seeing [Unhandled promise rejection: Error: my error].

Kefir101 avatar Jul 02 '23 17:07 Kefir101

@vitalets What do you think I should test out next?

Kefir101 avatar Jul 07 '23 23:07 Kefir101

I've tried to reproduce it on https://github.com/Kefir101/Shortened-VeganChecker but was not able to run it. When running npm start and scanning qr code (ios) I'm getting error that there is no valid data. The output is following:

› Metro waiting on exp+veganchecker://expo-development-client/?url=http%3A%2F%2F192.168.10.13%3A8081
› Scan the QR code above with Expo Go (Android) or the Camera app (iOS)

I suppose this is because of exp+veganchecker:// scheme but I don't know how to fix it.

Lets do the following:

  1. could you log all texts that used for translation in 5-10 times before error occurs
  2. create fresh React Native app, include only @viatelst/google-translate-api and run translation in a loop of all these texts (with some delay to replicate how it occurs in VeganChecker)
  3. If error still occurs, paste these texts here and I will try to replicate myself. If there will be no error - we will continue search in VeganChecker

vitalets avatar Jul 09 '23 06:07 vitalets

@vitalets I was doing npx expo start instead, that might be why it didn't work for you.

Kefir101 avatar Jul 09 '23 20:07 Kefir101

@vitalets I was doing npx expo start instead, that might be why it didn't work for you.

Yes, that helped! Now I'm getting error:

iOS Bundling failed 9ms
Unable to resolve "./config.js" from "helperFunctions.js"

I see that config.js is in gitignore as it seems it contains some sensitive data. Is there way to run app somehow?

vitalets avatar Jul 10 '23 07:07 vitalets

Ah right, I’m using Google Vision which requires an API key so I hid it in the config file. But getting rid of that makes it hard to test, so I’m not sure how to proceed. I have gone on vacation so I will get back to this later, thank you so much for your help so far.

Kefir101 avatar Jul 23 '23 04:07 Kefir101