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

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
HW: ----
NextAction: ----
OS: ----
Priority: 2
Type: FeatureRequest

Blocking:
issue 5325
issue 6513



Sign in to add a comment
link

Issue 5532: User-unfriendly error messages when destructuring fails

Reported by marja@chromium.org, Oct 18 2016 Project Member

Issue description

1)

var a, b;
[a, b] = 8;

Gives:

TypeError: undefined is not a function
[a, b] = 8;
       ^
2)

function foo([a, b]) { }

foo(8);

Gives:

TypeError: undefined is not a function
function foo([a, b]) {
            ^
This works though:

var a, b;
({a, b} = 8);

And this too:

function foo({a, b}) { }

foo(8);

Other weird messages occur too:

3)

function foo() {}

var a, b;
[a, b] = new foo();

Gives:
TypeError: foo is not a function
[a, b] = new foo();
         ^

4)

var a, b;
[a, b] = undefined;

TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
[a, b] = undefined;
         ^
 

Comment 1 by adamk@chromium.org, Oct 18 2016

 Issue 5519  has been merged into this issue.

Comment 2 by adamk@chromium.org, Oct 18 2016

Cc: littledan@chromium.org adamk@chromium.org ca...@igalia.com
 Issue 5385  has been merged into this issue.

Comment 3 by adamk@chromium.org, Oct 18 2016

Labels: -Type-Bug Type-FeatureRequest

Comment 4 by adamk@chromium.org, Oct 19 2016

Agreed that these messages are not great. Would be interested in hearing thoughts on how to prioritize error message fixing vs other work, though.

Comment 5 by gsat...@chromium.org, Oct 27 2016

 Issue 5578  has been merged into this issue.

Comment 6 by adamk@chromium.org, Oct 27 2016

Cc: neis@chromium.org

Comment 7 by gsat...@chromium.org, Oct 27 2016

Cc: gsat...@chromium.org

Comment 8 by adamk@chromium.org, Nov 3 2016

Owner: ----
Status: Available (was: Assigned)

Comment 9 by gsat...@chromium.org, Feb 15 2017

 Issue 5973  has been merged into this issue.

Comment 10 by hablich@chromium.org, Mar 23 2017

Labels: Priority-2

Comment 11 Deleted

Comment 12 by aneil.ma...@gmail.com, Mar 28 2017

Yes, please.  FWIW, I filled out an issue on the NodeJs Github: https://github.com/nodejs/node/issues/12098

Comment 13 by gsat...@chromium.org, Mar 30 2017

Blocking: 5325

Comment 14 by kozyatinskiy@chromium.org, Jun 14 2017

Cc: kozyatinskiy@chromium.org
 Issue chromium:733252  has been merged into this issue.

Comment 15 by gsat...@chromium.org, Jun 21 2017

Blocking: 6513

Comment 16 by gsat...@chromium.org, Jun 28 2017

More examples from https://github.com/nodejs/node/issues/13964:

1)  function f() { return 6; }
    let [a,b]=f();  // TypeError: f is not a function

2)  function f() { return null; }
    let [a,b]=f();  // Cannot read property 'Symbol(Symbol.iterator)' of null

Comment 17 by bugdroid1@chromium.org, Jul 6 2017

Project Member
The following revision refers to this bug:
  https://chromium.googlesource.com/v8/v8.git/+/d8e1c4840c68da509d00099741f70445f33fa502

commit d8e1c4840c68da509d00099741f70445f33fa502
Author: Sathya Gunasekaran <gsathya@chromium.org>
Date: Thu Jul 06 19:57:44 2017

[parser] Improve error message for destructuring non iterable

Print the object that is being destructured and update the error 
message.

Previously,
  d8> var [a] = {}
  (d8):1: TypeError: [Symbol.iterator] is not a function

Now,
  d8> var [a] = {}
  (d8):1: TypeError: {} is not iterable

Bug: v8:6513, v8:5532
Change-Id: I5cbfe7c7e20632bce1a48bd38a1b0c98d0ff0660
Reviewed-on: https://chromium-review.googlesource.com/557370
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Reviewed-by: Caitlin Potter <caitp@igalia.com>
Cr-Commit-Position: refs/heads/master@{#46457}
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/ast/ast.h
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/ast/prettyprinter.cc
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/ast/prettyprinter.h
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/messages.h
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/parsing/pattern-rewriter.cc
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/src/runtime/runtime-internal.cc
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/cctest/interpreter/bytecode_expectations/AsyncGenerators.golden
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/cctest/interpreter/bytecode_expectations/ForAwaitOf.golden
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/cctest/interpreter/bytecode_expectations/ForOf.golden
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/cctest/interpreter/bytecode_expectations/ForOfLoop.golden
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/cctest/interpreter/bytecode_expectations/Generators.golden
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-number.out
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-object-literal-complex.js
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-object-literal-complex.out
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-object-literal.js
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-object-literal.out
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/destructuring-array-non-iterable-object.out
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/for-of-non-iterable.js
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/for-of-non-iterable.out
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/message/get-iterator1.out
[add] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/mjsunit/harmony/async-for-of-non-iterable.js
[modify] https://crrev.com/d8e1c4840c68da509d00099741f70445f33fa502/test/webkit/exception-for-nonobject-expected.txt

Sign in to add a comment