-
Notifications
You must be signed in to change notification settings - Fork 338
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
Conversation
Hi. Thanks for getting this started! I think it would be easier to start this by first adding a test that expects web-ext/tests/unit/test.errors.js Line 43 in ee197c4
The test suite output is going to be messy when you work on this feature because the function,
|
@kumar303 Hi. I tried to do what you said but I can't resolve the travis build issues |
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. |
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 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) { |
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.
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;
}
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.
You could possibly even use Array#includes()
, which I think is supported in Firefox 43+.
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.
NodeJS is our target platform with 4.0 being the minimum. I just checked and sadly 4.0 doesn't have this function.
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 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; |
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.
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.
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.
Done
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. |
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 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; |
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 be errno: number
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.
Done.
errno: string; | ||
constructor() { | ||
super('pretend this is a system error'); | ||
this.errno = 'SOME_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.
this should be something like this.errno = 53
, which means ENOTEMPTY
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.
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) => { |
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.
and then this would need to be onlyErrorsWithCode(53, ...)
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.
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) => { |
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.
and this would need updating too
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.
Done.
@@ -76,6 +98,17 @@ describe('errors', () => { | |||
}); | |||
}); | |||
|
|||
it('throws errors that are not in an array of errno', () => { |
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 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.
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.
Removed.
@kumar303 Hi, the travis checks have failed . Can you take a look ? |
Ah , I see now . |
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:
|
@kumar303 Hi, |
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.
Looks great, thanks for all the follow-ups
Thanks for your contribution, @rackstar17! I've added it to our recognition page. |
Fixes #220