#The Unresolvable Promise (NOT SOLVED)

18 messages · Page 1 of 1 (latest)

tired beacon
#

I'm integrating internationalization into a discord bot with the typesafe-i18n library, but when I use the fetchT function (made by me), it never resolves.

  • The command:
import { Slash, execute } from 'sunar';
import { fetchT, getT, localizations } from '../utils/i18n';

const slash = new Slash({
    name: getT().ping.name(),
    description: getT().ping.description(),
    nameLocalizations: localizations((t) => t.ping.name()),
    descriptionLocalizations: localizations((t) => t.ping.description()),
});

execute(slash, async (interaction) => {
    await interaction.deferReply();
    const ping = interaction.client.ws.ping;

    console.log('Fetching translations...');
    const t = await fetchT(interaction);
    console.log('Translations fetched:', t); // This console log is never executed

    await interaction.editReply({ content: t.ping.reply({ ping }) });
});

export { slash };
  • The fetchT function:
export async function fetchT(target: FetchTTarget): Promise<TranslationFunctions> {
    if (target instanceof BaseInteraction) {
        console.log('target is instanceof BaseInteraction');
        console.log('Fetching locale...');
        const locale = await fetchLocale({
            user: target.user,
            guild: target.guild,
            channel: target.channel,
            interactionLocale: target.locale,
            interactionGuildLocale: target.guildLocale,
        });
        console.log('Locale fetched:', locale);
        console.log('Resolving locale...');
        const resolved = resolveLocale(locale);
        console.log('Locale resolved:', resolved);
        return resolved;
    }

    console.log('THIS SHOULD NOT BE SHOWN');

    if (target instanceof Message) {
        const locale = await fetchLocale({
            user: target.author,
            guild: target.guild,
            channel: target.channel,
        });
        return resolveLocale(locale);
    }

    if (target instanceof Guild) {
        const locale = await fetchLocale({ guild: target });
        return resolveLocale(locale);
    }

    if (target.isDMBased()) {
        const locale = await fetchLocale({ channel: target });
        return resolveLocale(locale);
    }

    const locale = await fetchLocale({ guild: target.guild, channel: target });

    return L[isLocale(locale) ? locale : baseLocale];
}
  • The logs:
Fetching translations...
target is instanceof BaseInteraction
Fetching locale...
Locale fetched: en-US
Resolving locale...
Locale resolved: [Function (anonymous)] {
  ping: {
    name: 'internationalization',
    description: 'Show the bot latency.',
    reply: 'The ping is {ping:number}ms.'
  }
}

No errors are output in the console nor are any errors being ignored.

Review the entire code or try it on your own machine:

https://github.com/taii03/the-unresolvable-promise

pallid minnowBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
dense eagle
#

there seems to be an issue with the load call

dense eagle
#

very weird, if i make fetchT return something that isn't a TranslationFunctions, the execution flows normally

#

for example...

export async function fetchT(target: FetchTTarget): Promise<TranslationFunctions> {
  // @ts-expect-error
  return undefined;
  // ...
}
dense eagle
#

this seems to be an issue with the library

#

i created a minimal example and it has the same issue

tired beacon
#

The getT function does work so I don't think it is an issue of the typesafe-i18n library LGpink_think mmm... it's so weird

#

Although at this point it must be a library problem

#

What I think is that it's somehow blocking the main thread

tired beacon
#

The Unresolvable Promise (NOT SOLVED)

edgy cave
edgy cave
#

And if you went that route in the first place you would‘ve learned that that library is unmaintained for almost a year now

tired beacon
#

But it works with the getT method that I made, so that's why I think it's not a library problem, the fetchT function uses the same methods as the getT and it doesn't work

edgy cave