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

TypeError: Cannot call method 'replace' of null #417

Closed
Rowno opened this issue May 10, 2014 · 7 comments · Fixed by #682
Closed

TypeError: Cannot call method 'replace' of null #417

Rowno opened this issue May 10, 2014 · 7 comments · Fixed by #682

Comments

@Rowno
Copy link

Rowno commented May 10, 2014

TypeError: Cannot call method 'replace' of null 
Please report this to https://github.com/chjj/marked. 
at Lexer.lex (/app/node_modules/marked/lib/marked.js:137:6) 
at Function.Lexer.lex (/app/node_modules/marked/lib/marked.js:128:16) 
at marked (/app/node_modules/marked/lib/marked.js:1201:31) 
at Object.PullRequestEvent (/app/lib/events.js:257:20) 
at /app/lib/events.js:41:42 
at Promise.apply (/app/node_modules/q/q.js:1120:26) 
at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:751:41) 
at /app/node_modules/q/q.js:1335:14 
at flush (/app/node_modules/q/q.js:108:17) 
at /app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:177:31 
@sbruchmann
Copy link

Can you share the code where the exception was thrown?

Since I’ve seen a similar stack trace very often, I’ll take a guess and say that the string you are passing to marked is either null or undefined.

@Rowno
Copy link
Author

Rowno commented May 10, 2014

Yeah, I think it was, but it was with data returned from the GitHub API so I can't be sure.

Here's where the exception was thrown: https://github.com/Rowno/aftermath/blob/master/lib/events.js#L257

@sbruchmann
Copy link

The quickest workaround I can think of is to use a logical OR operator (||) and provide an empty string literal when the corresponding value is null / undefined:

data.content = markdown(event.payload.pull_request.body || '');

@Rowno
Copy link
Author

Rowno commented May 10, 2014

Yeah, I was going to do that. I just opened the issue because I was asked to. 😉

@scottgonzalez
Copy link
Contributor

I feel like this comes up often enough that marked should just convert null/undefined to an empty string.

@bnvk
Copy link

bnvk commented Jan 31, 2016

Yup! Just encountered this issue in a lil tool that uses marked

/home/user/Tools/offline-issues/node_modules/marked/lib/marked.js:1226
    throw e;
    ^

TypeError: Cannot read property 'replace' of null
Please report this to https://github.com/chjj/marked.
    at Lexer.lex (/home/user/Tools/offline-issues/node_modules/marked/lib/marked.js:138:5)
    at Function.Lexer.lex (/home/user/Tools/offline-issues/node_modules/marked/lib/marked.js:129:16)
    at marked (/home/user/Tools/offline-issues/node_modules/marked/lib/marked.js:1218:31)
    at parseBody (/home/user/Tools/offline-issues/src/writehtml.js:58:16)
    at /home/user/Tools/offline-issues/src/writehtml.js:35:13
    at Array.forEach (native)
    at writehtml (/home/user/Tools/offline-issues/src/writehtml.js:34:10)
    at /home/user/Tools/offline-issues/src/index.js:132:7
    at /home/user/Tools/offline-issues/node_modules/cpr/node_modules/rimraf/node_modules/graceful-fs/graceful-fs.js:90:5
    at FSReqWrap.oncomplete (fs.js:82:15)

@joshbruce
Copy link
Member

Working toward resolution - closing to clean up issues.

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 a pull request may close this issue.

5 participants