-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib: AssertionError moved to internal/error #12906
Conversation
There is one test case which I've been trying to resolve but have been out of luck. Looks like the test suite regex matches the exception being thrown. Since |
lib/internal/errors.js
Outdated
} | ||
} | ||
|
||
function fail(actual, expected, message, operator, stackStartFunction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use const fail = require('assert').fail
instead of inline codes?
lib/internal/errors.js
Outdated
this.actual = options.actual; | ||
this.expected = options.expected; | ||
this.operator = options.operator; | ||
var stackStartFunction = options.stackStartFunction || assert.fail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use const
.
lib/internal/errors.js
Outdated
@@ -69,6 +93,7 @@ module.exports = exports = { | |||
Error: makeNodeError(Error), | |||
TypeError: makeNodeError(TypeError), | |||
RangeError: makeNodeError(RangeError), | |||
AssertionError: makeAssertionError(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're going to need the factory method in this case. The other ones are there just to reduce code duplication. Just define the class and export it directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Also there is a test case that depends on how the AssertionError
object was created (regex matching). How do I fix that? Earlier AssertionError
object were created like throw new AssertionError
, but now in assert.js
, I do it like this throw new error.AssertionError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can very well store the constructor reference in a variable named like the class, but that would be a hack!
lib/internal/errors.js
Outdated
@@ -41,6 +41,28 @@ function makeNodeError(Base) { | |||
}; | |||
} | |||
|
|||
class AssertionError extends Error { | |||
constructor(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fail linting... this needs a 2 character space indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can I just run the linter on my code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make lint
lib/internal/errors.js
Outdated
@@ -69,6 +91,7 @@ module.exports = exports = { | |||
Error: makeNodeError(Error), | |||
TypeError: makeNodeError(TypeError), | |||
RangeError: makeNodeError(RangeError), | |||
AssertionError: AssertionError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just AssertionError,
should suffice (it does not need the additional : AssertionError
bit)
AssertionError class is moved to interna/error in reference to the TODO in assert.js. This was suggested to get rid of the cyclic dependency between assert.js and internal/error.js
@jasnell done & done |
Before I pushed my changes. There were 4 test cases that were failing. After my changes there are 5 test cases failing. I know the reason why the 5th one is failing. I'm just not sure where to do the changes!
|
@fhalde I think you might be able to fix the CI by updating the third line in |
@@ -89,7 +56,8 @@ function fail(actual, expected, message, operator, stackStartFunction) { | |||
message = actual; | |||
if (arguments.length === 2) | |||
operator = '!='; | |||
throw new AssertionError({ | |||
const errors = lazyErrors(); | |||
throw new errors.AssertionError({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This is anyway export
ed. Why not just throw new assert. AssertionError({...});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember, there was a problem caused by cyclic dependency. Something wasn't initialized causing few test cases to fail. Let me check it again!
If everything looks good, i'll squash the commits. I guess GitHub has the feature of squashing the PR?? |
The commits can be squashed by whomever lands the PR |
AssertionError class is moved to interna/error in reference to the TODO in assert.js. This was suggested to get rid of the cyclic dependency between assert.js and internal/error.js PR-URL: #12906 Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 425aba4 |
AssertionError class is moved to interna/error in reference to the TODO in assert.js. This was suggested to get rid of the cyclic dependency between assert.js and internal/error.js PR-URL: #12906 Reviewed-By: James M Snell <jasnell@gmail.com>
AssertionError class is moved to interna/error in reference to the TODO in assert.js. This was suggested to get rid of the cyclic dependency between assert.js and internal/error.js PR-URL: #12906 Reviewed-By: James M Snell <jasnell@gmail.com>
AssertionError class is moved to interna/error in reference to the TODO in assert.js. This was suggested to get rid of the cyclic dependency between assert.js and internal/error.js PR-URL: #12906 Reviewed-By: James M Snell <jasnell@gmail.com>
Opting to not land this on v6.x... lmk if we should backport |
AssertionError class is moved to internal/error
in reference to the TODO in assert.js. This was
suggested to get rid of the cyclic dependency
between assert.js and internal/error.js
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert