Weird behavior, works in localhost

I have the following TypeScript function that INSERT to D1:
// eslint-disable-next-line
async function handleCreateAccount(data: any, accountRepo: AccountRepo) {
try {
const account = toAccount(data);
console.log(`Creating account: ` + JSON.stringify(account));

await accountRepo.create(account);

console.log(`Created account: ` + JSON.stringify(account));
} catch (error) {
console.log(`Error: ` + JSON.stringify(error));
}
}
...
(in AccountRepo)
async create(account: Account): Promise<void> {
await this.db.prepare(this.CREATE).bind(...).run();
}
// eslint-disable-next-line
async function handleCreateAccount(data: any, accountRepo: AccountRepo) {
try {
const account = toAccount(data);
console.log(`Creating account: ` + JSON.stringify(account));

await accountRepo.create(account);

console.log(`Created account: ` + JSON.stringify(account));
} catch (error) {
console.log(`Error: ` + JSON.stringify(error));
}
}
...
(in AccountRepo)
async create(account: Account): Promise<void> {
await this.db.prepare(this.CREATE).bind(...).run();
}
The function works perfectly in localhost, but on the cloud stops after printing "Creating account: (JSON)"—it never prints "Created account: (JSON)". No error at all. How do I troubleshoot this? EDIT: I found the culprit. I forgot to add "await" when refactoring the code that calls handleCreateAccount. But why it works locally (albeit wrong) but not when deployed?
1 Reply
Razboy20
Razboy205mo ago
Take my answer with a grain of salt as I don’t work on D1, but I would expect local development to potentially run this binding communication faster/synchronously, in comparison to on remote (where communication has to actually occur)

Did you find this page helpful?