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

Change to different function length check #51

Merged
merged 1 commit into from
Jul 17, 2019
Merged

Change to different function length check #51

merged 1 commit into from
Jul 17, 2019

Conversation

levibostian
Copy link
Contributor

Today as I was using connect-sequence, I was hit with an exception:

[ integration]       ERROR: Extra: (none), message: str.split is not a function, stack: TypeError: str.split is not a function
[ integration]           at isErrorHandler (/Users/levibostian/code/ExpressjsBlanky/node_modules/connect-sequence/lib/ConnectSequence.js:238:18)
[ integration]           at nextHandler (/Users/levibostian/code/ExpressjsBlanky/node_modules/connect-sequence/lib/ConnectSequence.js:91:13)
[ integration]           at ConnectSequence.run (/Users/levibostian/code/ExpressjsBlanky/node_modules/connect-sequence/lib/ConnectSequence.js:67:22)

This crash occurred at the code:

function isErrorHandler (cb) {
  var str = cb.toString()
  var args = str.split('(')[1].split(')')[0].split(',')
  return args.length === 4
}

After debugging, I realized that cb is an instance of an express-validator middleware. For some reason, when calling cb.toString() the result was not a string, but another function according to the debugger.

So, after doing some research on "how to count the number of parameters in a function", I found this method that I used in this PR.

After running my unit and integration tests on my application, everything seems to work well without the crash. I also checked the debugger and cb.length returns an integer successfully. I expected a length of 3 for my express validator middleware and that is what successfully was returned back.

@rbecheras
Copy link
Member

Hi !

Thank you for the PR.

Could you just fix the trailing spaces and push again to validate the travis CI please ?

lib/ConnectSequence.js
line 236:31	Trailing spaces not allowed.
✖ 1 errors	⚠ 0 warnings

https://travis-ci.org/sirap-group/connect-sequence/builds/551935612?utm_source=github_status&utm_medium=notification

Then I'll merge it.

@levibostian
Copy link
Contributor Author

@rbecheras, done.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c147555 on levibostian:error-handler-fix into 8b0490d on sirap-group:master.

@levibostian
Copy link
Contributor Author

This PR is ready for another review, @rbecheras. Thanks!

@rbecheras
Copy link
Member

Thank you very much @levibostian :)

I merge

@rbecheras rbecheras merged commit dacd6d9 into sirap-group:master Jul 17, 2019
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.

None yet

3 participants