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

fix: Added errno for errors with specific codes #488

Merged
merged 4 commits into from
Sep 25, 2016

Conversation

rackstar17
Copy link
Contributor

@rackstar17 rackstar17 commented Sep 15, 2016

Fixes #220

@coveralls
Copy link

coveralls commented Sep 15, 2016

Coverage Status

Coverage decreased (-8.6%) to 91.429% when pulling 7d4c0e6 on rackstar17:fix/220 into 0d1b824 on mozilla:master.

@kumar303
Copy link
Contributor

Hi. Thanks for getting this started!

I think it would be easier to start this by first adding a test that expects errno to be caught. You could model the test on this one:

it('catches errors having a code', () => {

The test suite output is going to be messy when you work on this feature because the function, onlyErrorsWithCode(), is used by many other tests. To hide the irrelevant failures, you can run only the tests for this specific function like this:

./node_modules/.bin/mocha -r babel-core/register tests/unit/test.errors.js

@coveralls
Copy link

coveralls commented Sep 18, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 7d2e6b8 on rackstar17:fix/220 into 0d1b824 on mozilla:master.

@rackstar17
Copy link
Contributor Author

@kumar303 Hi. I tried to do what you said but I can't resolve the travis build issues
I also tried to run the test.errors.js file as you mentioned and locally all the tests were passed for test.errors.js . Can you help me with it ?

@coveralls
Copy link

coveralls commented Sep 19, 2016

Coverage Status

Coverage decreased (-0.2%) to 99.838% when pulling d62b2a5 on rackstar17:fix/220 into cb50f9f on mozilla:master.

@coveralls
Copy link

coveralls commented Sep 19, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling d330f9e on rackstar17:fix/220 into cb50f9f on mozilla:master.

@kumar303
Copy link
Contributor

The test failure may have been a timeout caused by slowness in the TravisCI system, not with your patch. I have restarted the test to see if it still fails repeatedly.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

This is looking really good, thanks for following up.

You also need to add a test that checks for errno in an array of codes. You can model that test after this one. Because you used a second if for the errno Array check (instead of an else), the code coverage checker did not catch this omission -- tricky!

if (codeWanted.indexOf(error.code) !== -1) {
throwError = false;
}
if (codeWanted.indexOf(error.errno) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can group these statements to make the code more concise and less repetitive. Example:

if (codeWanted.indexOf(error.code) !== -1 ||
    codeWanted.indexOf(error.errno) !== -1) {
  throwError = false;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

You could possibly even use Array#includes(), which I think is supported in Firefox 43+.

Copy link
Contributor

Choose a reason for hiding this comment

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

NodeJS is our target platform with 4.0 being the minimum. I just checked and sadly 4.0 doesn't have this function.

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 added the || code to reduce the repetitiveness of if statements but there was this issue of not having more than 80 columns in a single line.
It could be done this way, didn't think of that earlier .
Done.

@@ -34,9 +34,11 @@ describe('errors', () => {

class ErrorWithCode extends Error {
code: string;
errno: string;
Copy link
Contributor

@kumar303 kumar303 Sep 19, 2016

Choose a reason for hiding this comment

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

instead of editing this class, I think you need to create a new class named something like ErrorWithErrno and add errno to that one only. Otherwise, the existing tests for error codes will not be as effective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@kumar303
Copy link
Contributor

... may have been a timeout caused by slowness in the TravisCI system

Yes, this was it. I restarted the build and the tests are passing now. Sorry for the confusion! This doesn't happen too often but it's a known problem with this test.

@coveralls
Copy link

coveralls commented Sep 19, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling b5a8f00 on rackstar17:fix/220 into cb50f9f on mozilla:master.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

This is really close, thanks for the follow-ups. I requested some changes to make the tests more realistic.

@@ -40,13 +40,28 @@ describe('errors', () => {
}
}

class ErrorWithErrno extends Error {
errno: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be errno: number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

errno: string;
constructor() {
super('pretend this is a system error');
this.errno = 'SOME_CODE';
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be something like this.errno = 53, which means ENOTEMPTY

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

it('catches errors having a code', () => {
return Promise.reject(new ErrorWithCode())
.catch(onlyErrorsWithCode('SOME_CODE', (error) => {
assert.equal(error.code, 'SOME_CODE');
}));
});

it('catches errors having a error no', () => {
return Promise.reject(new ErrorWithErrno())
.catch(onlyErrorsWithCode('SOME_CODE', (error) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

and then this would need to be onlyErrorsWithCode(53, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -65,6 +80,13 @@ describe('errors', () => {
}));
});

it('catches errors having one of many errno', () => {
return Promise.reject(new ErrorWithErrno())
.catch(onlyErrorsWithCode(['OTHER_CODE', 'SOME_CODE'], (error) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

and this would need updating too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -76,6 +98,17 @@ describe('errors', () => {
});
});

it('throws errors that are not in an array of errno', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to include this test. It doesn't introduce any new coverage since the previous one already checks that an array of mismatching codes does not catch any error at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@rackstar17
Copy link
Contributor Author

@kumar303 Hi, the travis checks have failed . Can you take a look ?
Thanks.

@rackstar17
Copy link
Contributor Author

Ah , I see now .
The thing you suggested to make errno: number , the onlyErrorsWithCode expects it's parameter to be string or array of strings and here we are passing number .

@kumar303
Copy link
Contributor

Yes, exactly, we use Flow to incorporate static typing into the code. You'll need to specify that codeWanted can take an array of either strings or numbers. It's a bit cryptic due to polymorphism so here is the typing fix:

codeWanted: string | Array<string|number>

@coveralls
Copy link

coveralls commented Sep 21, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling b4fe6f2 on rackstar17:fix/220 into da5e0f0 on mozilla:master.

@rackstar17
Copy link
Contributor Author

@kumar303 Hi,
The tests have passed , Can you review it ?
Thanks .

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for all the follow-ups

@kumar303 kumar303 self-assigned this Sep 25, 2016
@kumar303 kumar303 merged commit 0d4141b into mozilla:master Sep 25, 2016
@atsay
Copy link

atsay commented Sep 26, 2016

Thanks for your contribution, @rackstar17! I've added it to our recognition page.

@rackstar17 rackstar17 deleted the fix/220 branch September 26, 2016 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants