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

Await is only valid in async functions and the top level bodies of modules #9

Closed
StefanoRausch opened this issue Oct 4, 2023 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@StefanoRausch
Copy link

Describe the bug

Async function calls are not possible in the run start block.

To Reproduce

I am trying to run the following code:

%% run start 0

```js
const {reverse} = await self.require.import("[[user.script.fp.reverse.mjs]]")

const a = [1, 2, 3]
const b = reverse(a)

return `a = ${a}\nb = ${b}`
```

%%

Run generates the following end tag metadata:

%% run end

error: await is only valid in async functions and the top level bodies of modules

%%

Expected behavior

The output should be:

a = 1,2,3
b = 3,2,1

The following Templater snippet works as expected:

<%*
const {reverse} = await self.require.import("[[user.script.fp.reverse.mjs]]")

const a = [1, 2, 3]
const b = reverse(a)

tR += `a = ${a}\nb = ${b}`
_%>

Additional context

SYSTEM INFO:

Obsidian version: v1.4.14
Installer version: v1.4.14
Operating system: Windows 11 Home Single Language 10.0.22621
Login status: logged in
Catalyst license: supporter
Insider build toggle: on
Live preview: on
Legacy editor: off
Base theme: light
Community theme: Minimal v7.2.3
Snippets enabled: 33
Restricted mode: off
Plugins installed: 49
Plugins enabled: 43
@StefanoRausch StefanoRausch added the bug Something isn't working label Oct 4, 2023
@HananoshikaYomaru
Copy link
Owner

this is indeed a bug.

@HananoshikaYomaru HananoshikaYomaru self-assigned this Oct 4, 2023
@HananoshikaYomaru
Copy link
Owner

HananoshikaYomaru commented Oct 4, 2023

@StefanoRausch I think I know how to fix this. But I can see that you are using some advanced techniques. Do you want to have a online call so that I can understand you needs and also I put this in the Advanced usage section of the readme?

@HananoshikaYomaru
Copy link
Owner

HananoshikaYomaru commented Oct 4, 2023

this is fixed in 1.0.5

@StefanoRausch
Copy link
Author

Sorry, I was out and about.

I updated to version 1.0.5 and Run now shows me the following:

image

It looks like the plugin is not waiting for the promise to resolve.

I am available right now, if you want to chat.

@HananoshikaYomaru
Copy link
Owner

come to my discord -> https://discord.gg/VYNGp7Z5

@HananoshikaYomaru
Copy link
Owner

I am not available right now, but leave me a message in the channel and we will figure out a time.

@HananoshikaYomaru
Copy link
Owner

that is weird, I have no problem resolving the promise.

CleanShot 2023-10-04 at 13 55 17

@StefanoRausch
Copy link
Author

StefanoRausch commented Oct 5, 2023

Version 1.0.5 does not resolve the issue. Reopened: see #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants