Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Errors.add should throw on invalid calls #744

Merged

Conversation

qfox
Copy link
Member

@qfox qfox commented Nov 4, 2014

To simplify rules debugging, prevent dumb mistakes and crashes in error reporters.

@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from e14f790 to ee4dfd6 Compare November 4, 2014 11:23
qfox pushed a commit to qfox/node-jscs that referenced this pull request Nov 4, 2014
To simplify rules debugging and prevent dumb mistakes.

Fixes jscs-dev#743
Closes jscs-dev#744
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) when pulling ee4dfd6 on zxqfox:hotfix/prevent-crashes-in-error-reporters into cda4d10 on jscs-dev:master.

@@ -28,6 +28,10 @@ Errors.prototype = {
line = line.line;
}

if (typeof line !== 'number' || (column && typeof column !== 'number')) {
Copy link
Member

Choose a reason for hiding this comment

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

Why the '(column & & ' clause?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, because it's declared as optional in jsdoc. Probably it isn't right.

Copy link
Member

Choose a reason for hiding this comment

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

K. Makes sense. Please comment above that line with that explanation.

Can you add a test for this please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but I don't know where to place it. In string-checkers?
Also test will look like:

        function makeThrowingEsprima(description, line, column) {
            return {
                parse: function() {
                    var error = new Error(description);
                    error.lineNumber = line;
                    error.column = column;
                    throw error;
                }
            };
        };

        it('should throw an error on errors.add', function() {
            checker = new Checker({ esprima: makeThrowingEsprima('object') });
            checker.registerDefaultRules();

            var errors = checker.checkString('import { foo } from "bar";');
            var error = errors.getErrorList()[0];

            // check error...
        });

Right?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, because it's declared as optional in jsdoc. Probably it isn't right.

If it is optional, write column === undefined, don't go with implicit boolean conversion.

Copy link
Member

Choose a reason for hiding this comment

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

Invalid error location data: <' + message + '> at <' + line + '>, <' + column + '>

I think this is a bad error message.

I would go for more specific errors like "Unable to add an error, column should be a number", "Unable to add an error, line should be a number".

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I'll change message.

It was a useful proposal with minimal functionality.

@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from ee4dfd6 to 443e68a Compare November 4, 2014 22:47
qfox pushed a commit to qfox/node-jscs that referenced this pull request Nov 4, 2014
- simplify rules debugging to prevent dumb mistakes and crashes in error reporters.
- set 0 as column in rules/disallow-mixed-spaces-and-tabs
- add throwing tests for add method

Fixes jscs-dev#743
Closes jscs-dev#744
@qfox
Copy link
Member Author

qfox commented Nov 4, 2014

@mdevils @mrjoelkemp Guys, I'm done. Need review.

@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from 443e68a to 44effc7 Compare November 4, 2014 22:54
qfox pushed a commit to qfox/node-jscs that referenced this pull request Nov 4, 2014
- simplify rules debugging to prevent dumb mistakes and crashes in error reporters.
- set 0 as column in rules/disallow-mixed-spaces-and-tabs
- add throwing tests for add method

Fixes jscs-dev#743
Closes jscs-dev#744
@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from 44effc7 to daded70 Compare November 4, 2014 23:07
qfox pushed a commit to qfox/node-jscs that referenced this pull request Nov 4, 2014
- add method now throws on calls with invalid values
- set 0 as column in rules/disallow-mixed-spaces-and-tabs
- add throwing tests for add method

Fixes jscs-dev#743
Closes jscs-dev#744
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling daded70 on zxqfox:hotfix/prevent-crashes-in-error-reporters into cda4d10 on jscs-dev:master.

}

it('should throw an error on invalid line', function() {
var checker = new Checker({ esprima: makeThrowingEsprima('msg', 0) });
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why makeThrowingEsprima is necessary. Why can't you just call errors.add with arguments that trigger the exception?

Something like:

assert.throws(function() {
  errors.add('foo', -1, -1);
})

All of the arguments that you passed to makeThrowingEsprima could be passed to errors.add instead.

Would that not work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, yes. Idk why I did it like that. Gonna fix that.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mrjoelkemp fixed, thanks!

@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from 43453b2 to 1fe8870 Compare November 5, 2014 11:15
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling 1fe8870 on zxqfox:hotfix/prevent-crashes-in-error-reporters into f68fb06 on jscs-dev:master.

@mdevils
Copy link
Member

mdevils commented Nov 5, 2014

Great job. The last thing, can you use assert module there please.

Example: https://github.com/jscs-dev/node-jscs/blob/master/lib/config/configuration.js#L200

@qfox
Copy link
Member Author

qfox commented Nov 5, 2014

@mdevils Sure. I was afraid it's not possible to use there. Going to do that.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling 4f1a14b on zxqfox:hotfix/prevent-crashes-in-error-reporters into f68fb06 on jscs-dev:master.

@mdevils
Copy link
Member

mdevils commented Nov 5, 2014

Looks good to me.

@mrjoelkemp, @markelog, OK to merge?

@qfox
Copy link
Member Author

qfox commented Nov 5, 2014

@mdevils I would squash before merging. Should I?

@mdevils
Copy link
Member

mdevils commented Nov 5, 2014

Yep :)

- `add` method now throws on calls with invalid values
- set 0 as column in rules/disallow-mixed-spaces-and-tabs
- `add` throwing tests for add method

Fixes jscs-dev#743
Closes jscs-dev#744
@qfox qfox force-pushed the hotfix/prevent-crashes-in-error-reporters branch from 4f1a14b to 1ac6e34 Compare November 5, 2014 16:21
@qfox
Copy link
Member Author

qfox commented Nov 5, 2014

Done.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) when pulling 1ac6e34 on zxqfox:hotfix/prevent-crashes-in-error-reporters into f68fb06 on jscs-dev:master.

@mrjoelkemp
Copy link
Member

@mdevils looks good. feel free to merge.

@zxqfox Great job! Thanks!

@mdevils mdevils merged commit 1ac6e34 into jscs-dev:master Nov 5, 2014
@mdevils
Copy link
Member

mdevils commented Nov 5, 2014

Merged, thanks!

@qfox qfox deleted the hotfix/prevent-crashes-in-error-reporters branch November 5, 2014 19:28
@qfox
Copy link
Member Author

qfox commented Nov 5, 2014

You are welcome 🌴

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants