Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Truffle console: Assignments involving an await return undefined #3349

Closed
haltman-at opened this issue Sep 8, 2020 · 15 comments
Closed

Truffle console: Assignments involving an await return undefined #3349

haltman-at opened this issue Sep 8, 2020 · 15 comments

Comments

@haltman-at
Copy link
Contributor

Issue

In Truffle Console, if you enter an assignment expression, and the right-hand-side involves an await, the return value incorrectly shows as undefined.

Both the assignment and the await seems to be necessary. For instance, both x = 3 and await 3 correctly show 3; however, x = await 3 shows undefined.

This also happens in more complicated assignments involving await, such as x = (await 3) + 1. Of course, note that more complicated expressions like this may not work at all, as per #1546! Indeed I assume this issue is probably related to #1546 somehow... (but maybe it's easier to fix? IDK).

Steps to Reproduce

Open truffle console in a Truffle project.

Enter:

x = await 3

x = (await 3) + 1

Expected Behavior

The return values should be 3 and 4, respectively.

Actual Results

The return values are both undefined.

Environment

  • Operating System: Release Linux Mint 20 Ulyana 64-bit
  • Ethereum client: Ganache CLI v6.10.1 (ganache-core: 2.11.2)
  • Truffle version (truffle version): 5.1.41
  • node version (node --version): v10.15.3
  • npm version (npm --version): 6.14.5
@cds-amal
Copy link
Member

cds-amal commented Jun 9, 2021

@haltman-at , It looks like the result of the global variable cleanup for our top-level await workaround. That void operator captures the result of delete and returns undefined

@haltman-at
Copy link
Contributor Author

So now that the problem has finally been identified, the question is whether to use a targeted fix that just fixes this, or, since we no longer support Node 8, to just rewrite all this to use --experimental-repl-await and finally fix #1546 in its entirety.

@cds-amal
Copy link
Member

--experimental-repl-await looks cool! Will have to verify if it handle's the repl module

@eggplantzzz
Copy link
Contributor

eggplantzzz commented Jun 10, 2021

I would love to get rid of the parsing done on the Truffle side to deal with await! Can we do this?

@gnidan
Copy link
Contributor

gnidan commented Jun 10, 2021

Unfortunately, there's no way of doing --experimental-repl-await via the require("repl") library interface.

@haltman-at
Copy link
Contributor Author

Damn. OK, I guess targeted solution it'll have to be then, and #1546 will just remain open...

@cds-amal
Copy link
Member

actually, this may not be true @gnidan . I just ran a test and it works for v10, 12, & 14

@haltman-at
Copy link
Contributor Author

@cds-amal, I think that statement needs some elaboration!

What Amal actually did is not to somehow pass the equivalent of the --experimental-repl-await flag to the repl library, but rather to pass the actual --experimental-repl-await flag to the instance of Node that's running Truffle! That is to say, we could add it to the shebang line in @truffle/core!

It's a little unclear whether this suffices for our purposes, but it just might... after all, it's not like we create a REPL from any other package!

@cds-amal
Copy link
Member

@haltman-at you're correct. The outer node process receives the --experimental-repl-await, benefiting from its features but those benefits are not passed on to the repl library when using a custom eval function.

@haltman-at
Copy link
Contributor Author

Oh, so it doesn't work after all? Damn, that's disappointing...

@haltman-at
Copy link
Contributor Author

Btw, apparently as of Node 16, --experimental-repl-await is no longer experimental and is now the default. So, uh, once we only support Node 16 and later (whenever that might be), then we'll finally be able to get rid of all our special await-handling code. :P

@mdg215199
Copy link

This is still an issue, is there any way to be able to use the the truffle console? From what i'm reading... i think truffle console is pretty much half pointless at the moment? Or, am i reading this wrong

@cds-amal
Copy link
Member

truffle console and truffle develop starts a configured node REPL to interact with and observe smart contracts. These are useful things for developing and learning about contracts you write and interact with. The issue, tracked here, has to do with how the node REPL displays when executing a top level await. At most, it is a minor inconvenience that shouldn't detract from interacting with smart contracts.

Check out Filip's use of truffle console in this video series

@mdg215199
Copy link

Thank you for the video, I had to watch it a second time, as the first, I was skipping through instead of fully watching the last part of it. Absolutely solved the issue I was having.

@cliffoo
Copy link
Contributor

cliffoo commented Jul 15, 2022

Fixed in pull#5270 and in the latest release v5.5.22. Thanks @haltman-at!

@cliffoo cliffoo closed this as completed Jul 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants