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

lib: AssertionError moved to internal/error #12906

Closed
wants to merge 2 commits into from
Closed

Conversation

fhalde
Copy link
Contributor

@fhalde fhalde commented May 8, 2017

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), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

assert

@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels May 8, 2017
@fhalde
Copy link
Contributor Author

fhalde commented May 8, 2017

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 AssertionError has moved to a different module, the fully qualified name doesn't match up which results in the test failure.

}
}

function fail(actual, expected, message, operator, stackStartFunction) {
Copy link
Contributor

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?

this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
var stackStartFunction = options.stackStartFunction || assert.fail;
Copy link
Member

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.

@@ -69,6 +93,7 @@ module.exports = exports = {
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
RangeError: makeNodeError(RangeError),
AssertionError: makeAssertionError(),
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

@@ -41,6 +41,28 @@ function makeNodeError(Base) {
};
}

class AssertionError extends Error {
constructor(options) {
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make lint

@@ -69,6 +91,7 @@ module.exports = exports = {
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
RangeError: makeNodeError(RangeError),
AssertionError: AssertionError,
Copy link
Member

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
@fhalde
Copy link
Contributor Author

fhalde commented May 10, 2017

@jasnell done & done

@jasnell
Copy link
Member

jasnell commented May 11, 2017

@fhalde
Copy link
Contributor Author

fhalde commented May 11, 2017

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!

release test-process-exit checks for the error being thrown by assert ( uses regex match to check the failure ). Since the AssertionError has been moved to a new file, the regex no longer succeeds.

@addaleax
Copy link
Member

@fhalde I think you might be able to fix the CI by updating the third line in test/message/error_exit.out according to the failure, i.e. turn throw new AssertionError into throw new errors.AssertionError?

@@ -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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This is anyway exported. Why not just throw new assert. AssertionError({...});

Copy link
Contributor Author

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!

@thefourtheye
Copy link
Contributor

@fhalde
Copy link
Contributor Author

fhalde commented May 23, 2017

If everything looks good, i'll squash the commits. I guess GitHub has the feature of squashing the PR??

@jasnell
Copy link
Member

jasnell commented May 23, 2017

The commits can be squashed by whomever lands the PR

jasnell pushed a commit that referenced this pull request May 23, 2017
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>
@jasnell
Copy link
Member

jasnell commented May 23, 2017

Landed in 425aba4

@jasnell jasnell closed this May 23, 2017
jasnell pushed a commit that referenced this pull request May 23, 2017
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>
jasnell pushed a commit that referenced this pull request May 23, 2017
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>
jasnell pushed a commit that referenced this pull request May 28, 2017
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>
@MylesBorins
Copy link
Contributor

Opting to not land this on v6.x... lmk if we should backport

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. errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants