TriliumNext / Notes

Build your personal knowledge base with TriliumNext Notes
https://triliumnext.github.io/Docs/
GNU Affero General Public License v3.0
1.09k stars 61 forks source link

(Bug report) api.runOnBackend error says don't use `async` but it's not used #490

Open maphew opened 1 month ago

maphew commented 1 month ago

TriliumNext Version

0.90.7-beta

What operating system are you using?

Windows

What is your setup?

Local (no sync)

Operating System Version

win 11 pro (10.0.22631 N/A Build 22631)

Description

I'm attempting to get command-palette script working with Trilium Next 0.90.7-beta and am getting this error:

Error: You're passing an async function to api.runOnBackend() which will likely not work as you intended. Either make the function synchronous (by removing 'async' keyword), or use api.runAsyncOnBackendWithManualTransactionHandling()

Likely the error is their responsibility however in investigating I don't see how to follow the advice in the error message, so maybe the problem is shared.

The code triggering the message appears to be:

async function getAvailableNotes(query) {
  const noteObjs = await api.runOnBackend(searchNotes, [query]);
  return noteObjs;
}
//...snip...
  async showCommands(query) {
    const commands = await api.runOnBackend(getAvailableCommands, [query.trim()]);
    await this.renderItems(commands);
  }

However async keyword is not being used, so how can it be removed?


xref https://github.com/justyns/trilium-scripts/issues/12

Error logs

No response

maphew commented 1 month ago

I'm betraying my javascript ignorance, and readng incomprehension: the functions begin with async! I was looking for a parameter. At any rate, my question remains: what's the proper way to deal with this?