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

Prevent error when using --api & comments have no example code. #80

Merged
merged 1 commit into from Jan 18, 2013

Conversation

timoxley
Copy link
Contributor

Output if trying to use --api flag on anything that doesn't have example code in the comments:

/usr/local/share/npm/lib/node_modules/dox/lib/api.js:25
  code.forEach(function(block){
       ^
TypeError: Cannot call method 'forEach' of null
    at Object.module.exports [as api] (/usr/local/share/npm/lib/node_modules/dox/lib/api.js:25:8)
    at Socket.<anonymous> (/usr/local/share/npm/lib/node_modules/dox/bin/dox:46:30)
    at Socket.EventEmitter.emit (events.js:93:17)
    at Pipe.onread (net.js:418:51)

The offending line:

var code = buf.match(/^( {4}[^\n]+\n*)+/gm); // this may return null

code.forEach(function(block){
  var code = block.replace(/^ {4}/gm, '');
  buf = buf.replace(block, '```js\n' + code.trimRight() + '\n```\n');
});

Simply needs to ensure code is an array before doing the forEach. Patch includes previously failing test.

@matthewmueller
Copy link

+1

1 similar comment
@bencevans
Copy link

👍

tj added a commit that referenced this pull request Jan 18, 2013
Prevent error when using --api & comments have no example code.
@tj tj merged commit fbd74c2 into tj:master Jan 18, 2013
@tj
Copy link
Owner

tj commented Jan 18, 2013

doh!

@bencevans
Copy link

Cheers @timoxley & @visionmedia 🍺

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

4 participants