New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 664751 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Feature



Sign in to add a comment

Error for incorrect usage of await keyword is not helpful

Reported by kdzwinel@gmail.com, Nov 12 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36

Steps to reproduce the problem:
Run the scripts below in the DevTools console:

#1

async function test(){ return Promise.resolve(); }
await test();

#2

async function test(){ return Promise.resolve(); }
(function() { await test })()

What is the expected behavior?
There should be an error explaining that `await` cannot be used in the top-level scope (#1) and that the wrapper function needs an 'async' keyword (#2)

What went wrong?
Currently, an error being displayed, for both cases, is "Uncaught SyntaxError: Unexpected identifier".

Did this work before? No 

Chrome version: 54.0.2840.71  Channel: canary
OS Version: OS X 10.11.6
Flash Version:
 
Screen Shot 2016-11-12 at 10.03.26.png
31.1 KB View Download
Components: -Blink Blink>JavaScript>Language
Cc: krajshree@chromium.org
Labels: Needs-Feedback
Tested this issue in Mac 10.11.16 by using chrome reported version #54.0.2840.71 and latest canary #56.0.2919.0.

Steps followed to reproduce the issue are as follows:
-----------
1. Ran the below scripts in the DevTools console:

a. async function test(){ return Promise.resolve(); }
await test();

b. async function test(){ return Promise.resolve(); }
(function() { await test })()

2. Observed error in the reported version as "Uncaught SyntaxError: Unexpected token". The error differed in different chrome versions i.e from M50 till M45.

Attaching screenshots of different chrome versions for reference.

kdzwinel@ - Could you please verify the screenshots of different chrome versions and please let us know the expected result and the actual result.

Thanks...!!
56.0.2919.0.png
31.7 KB View Download
54.0.2840.71.png
88.9 KB View Download
50.0.2624.0.png
164 KB View Download
45.0.2404.0.png
128 KB View Download

Comment 3 by kdzwinel@gmail.com, Nov 18 2016

Older Chrome versions (54, 50, 45) do not support async/await by default. This bug is valid from version 55 - https://www.chromestatus.com/feature/5643236399906816 .

Screenshot for version 56 looks OK.


Actual result is showing "Uncaught SyntaxError: Unexpected identifier" error, expected result is showing "`await` cannot be used in the top-level scope" or "`await` cannot be used in a non-async function".

Mozilla is working on this bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=1317153

Cc: yangguo@chromium.org dehrenberg@chromium.org
Labels: -Type-Bug Type-Feature
Status: Available (was: Unconfirmed)
Not sure if this is something we want to change?
Cc: ca...@igalia.com
Owner: littledan@chromium.org

Comment 6 by kdzwinel@gmail.com, Nov 25 2016

FYI Firefox fixed that and will be showing "await is only valid in async functions" message instead.

https://bugzilla.mozilla.org/show_bug.cgi?id=1317153

Comment 7 by ca...@igalia.com, Nov 25 2016

I guess we could report a special error if we see that the last parsed token was `await` in the ReportUnidentifiedToken thing, but it seems hard to get it emitting a helpful error all the time.
Cc: -dehrenberg@chromium.org littledan@chromium.org
Labels: -OS-Mac OS-All
Owner: ----
This seems like a good idea to help people learn to use the feature, but I don't think it is essential to improve the message right this second. Not a ship blocker for async/await, but nice to have. Leaving it open as unassigned if anyone wants to work on it.
Cc: gsat...@chromium.org
Owner: gsat...@chromium.org
Status: Fixed (was: Available)
Fixed in 62a7c080d5348bf35a9e1dd3a84449bc51d154b1

Sign in to add a comment