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

assert: accommodate ES6 classes that extend Error #4166

Closed
wants to merge 1 commit into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Dec 6, 2015

assert.throws() and assert.doesNotThrow() blow up with a TypeError
if used with an ES6 class that extends Error.

Fixes: #3188

`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: nodejs#3188
@Trott
Copy link
Member Author

Trott commented Dec 6, 2015

Without the change to lib/assert.js, the test added here results in this:

assert.js:90
  throw new assert.AssertionError({
  ^
AssertionError: expected AnotherErrorType, received TypeError: Class constructors cannot be invoked without 'new'
    at Object.<anonymous> (/tmp/node/test/parallel/test-assert.js:362:3)
    at Module._compile (module.js:399:26)
    at Object.Module._extensions..js (module.js:406:10)
    at Module.load (module.js:345:32)
    at Function.Module._load (module.js:302:12)
    at Function.Module.runMain (module.js:431:10)
    at startup (node.js:138:18)
    at node.js:976:3

With the change here to lib/assert.js, the test passes, of course.

@Trott
Copy link
Member Author

Trott commented Dec 6, 2015

Pre-emptive strike: Yes, the Assert API is Locked. That means: Only fixes related to security, performance, or bug fixes will be accepted. This is a bug fix. The docs say that assert.throws() can take a constructor but it blows up if it is an ES6 class constructor. This fixes that issue. (The alternative is to update the docs to indicate that ES6 classes are not OK. I'd prefer this change, although we may also want to amend the docs to indicate that the constructor should be a constructor that inherits from Error.)

@Trott
Copy link
Member Author

Trott commented Dec 6, 2015

@Trott Trott added the assert Issues and PRs related to the assert subsystem. label Dec 6, 2015
@bnoordhuis
Copy link
Member

LGTM. There was a problem with the centos5-64 buildbot, probably a stray process hogging a port.

Trott added a commit to Trott/io.js that referenced this pull request Dec 9, 2015
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: nodejs#3188
PR-URL: nodejs#4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@Trott
Copy link
Member Author

Trott commented Dec 9, 2015

Landed in da5cdc2

@Trott Trott closed this Dec 9, 2015
Trott added a commit that referenced this pull request Dec 15, 2015
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: #3188
PR-URL: #4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@rvagg rvagg mentioned this pull request Dec 17, 2015
Trott added a commit to Trott/io.js that referenced this pull request Jan 17, 2016
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: nodejs#3188
PR-URL: nodejs#4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: #3188
PR-URL: #4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: #3188
PR-URL: #4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@MylesBorins MylesBorins mentioned this pull request Jan 19, 2016
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
Notable changes:

* assert
  -  accommodate ES6 classes that extend Error (Rich Trott) #4166
* build
  - add "--partly-static" build options (Super Zheng) #4152
* deps
  - backport 066747e from upstream V8 (Ali Ijaz Sheikh) #4655
  - backport 200315c from V8 upstream (Vladimir Kurchatkin) #4128
  - upgrade libuv to 1.8.0 (Saúl Ibarra Corretgé)
* docs
  - various updates landed in 70 different commits!
* repl
  - attach location info to syntax errors (cjihrig) #4013
  - display error message when loading directory (Prince J Wesley) #4170
* tests
  - various updates landed in over 50 commits
* util
  - allow lookup of hidden values (cjihrig) #3988
MylesBorins pushed a commit that referenced this pull request Jan 20, 2016
Notable changes:

* assert
  -  accommodate ES6 classes that extend Error (Rich Trott) #4166
* build
  - add "--partly-static" build options (Super Zheng) #4152
* deps
  - backport 066747e from upstream V8 (Ali Ijaz Sheikh) #4655
  - backport 200315c from V8 upstream (Vladimir Kurchatkin) #4128
  - upgrade libuv to 1.8.0 (Saúl Ibarra Corretgé)
* docs
  - various updates landed in 70 different commits!
* repl
  - attach location info to syntax errors (cjihrig) #4013
  - display error message when loading directory (Prince J Wesley) #4170
* tests
  - various updates landed in over 50 commits
* util
  - allow lookup of hidden values (cjihrig) #3988

PR-URL: #4768
MylesBorins pushed a commit that referenced this pull request Jan 20, 2016
Notable changes:

* assert
  -  accommodate ES6 classes that extend Error (Rich Trott) #4166
* build
  - add "--partly-static" build options (Super Zheng) #4152
* deps
  - backport 066747e from upstream V8 (Ali Ijaz Sheikh) #4655
  - backport 200315c from V8 upstream (Vladimir Kurchatkin) #4128
  - upgrade libuv to 1.8.0 (Saúl Ibarra Corretgé)
* docs
  - various updates landed in 70 different commits!
* repl
  - attach location info to syntax errors (cjihrig) #4013
  - display error message when loading directory (Prince J Wesley) #4170
* tests
  - various updates landed in over 50 commits
* util
  - allow lookup of hidden values (cjihrig) #3988

PR-URL: #4768
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError`
if used with an ES6 class that extends Error.

Fixes: nodejs#3188
PR-URL: nodejs#4166
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Notable changes:

* assert
  -  accommodate ES6 classes that extend Error (Rich Trott) nodejs#4166
* build
  - add "--partly-static" build options (Super Zheng) nodejs#4152
* deps
  - backport 066747e from upstream V8 (Ali Ijaz Sheikh) nodejs#4655
  - backport 200315c from V8 upstream (Vladimir Kurchatkin) nodejs#4128
  - upgrade libuv to 1.8.0 (Saúl Ibarra Corretgé)
* docs
  - various updates landed in 70 different commits!
* repl
  - attach location info to syntax errors (cjihrig) nodejs#4013
  - display error message when loading directory (Prince J Wesley) nodejs#4170
* tests
  - various updates landed in over 50 commits
* util
  - allow lookup of hidden values (cjihrig) nodejs#3988

PR-URL: nodejs#4768
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants