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

generators\html\write\filename.js can throw "TypeError: Cannot read property 'name' of undefined." #284

Open
ChrisDrostUSE opened this issue Jan 15, 2018 · 0 comments

Comments

@ChrisDrostUSE
Copy link

ChrisDrostUSE commented Jan 15, 2018

This is probably a niche case but I am just starting with DocumentJS, having something that already has some JSDoc comments put in, but probably is not at all structured appropriately. This is following the exact steps on documentjs.com directly, except that the 'document your code' stuff was already done and hence no file modifications have been made yet; I'm just running this in a project folder that already existed. It happens whether I use the documentjs.json from documentjs.com or whether I delete it wholesale as the API docs appear to state. It does seem to be confused also about where the output directory is, but I assume I will figure out ways to configure that.

When I am running documentjs in a debugger, I get some initial output:

No documentjs.json. Create one to configure its behavior.             generate_project.js:101
Generating docs at ..\docs                                            generate_project.js:147
FIND: README.md                                                       file_event_emitter.js:80
FIND: app.js                                                          file_event_emitter.js:80
BUILD: Using cache site\templates\99914b932bd37a50b983c5e7c90ae93ib   templates.js:64
FIND: libs\content-uuid.js                                            file_event_emitter.js:80
FIND: libs\forge.js                                                   file_event_emitter.js:80
FIND: libs\get-db.js                                                  file_event_emitter.js:80
FIND: routes\auth.js                                                  file_event_emitter.js:80
FIND: routes\forge.js                                                 file_event_emitter.js:80
FIND: static\autodesk.js                                              file_event_emitter.js:80
FIND: static\run-viewer.js                                            file_event_emitter.js:80
WARNING!!                                                             _default.js:129
There is no @requires tag. did you mean @return ?
WARNING!!                                                             _default.js:129
There is no @requires tag. did you mean @return ?
WARNING!!                                                             _default.js:129
There is no @requires tag. did you mean @return ?
WARNING!!                                                             _default.js:129
There is no @requires tag. did you mean @return ?
WARNING!!                                                             _default.js:129
There is no @throws tag. did you mean @this ?
BUILD: Getting build module                                           static_dist.js:88
Guessed parent 'libs\forge.js'. Set parent in your siteConfig.        clean_doc_map.js:47

At this point the debugger indeed pauses in filename.js (from generate.js:60 > doc_map.js:30 > doc_object.js:32) but it appears to be a normal, valid call.

Continuing past that, there is another line of output,

OUT: ..\docs\README.html                                              doc_object.js:35

and then the set of circumstances is set which will generate the TypeError: the parameter docObject is called as undefined.

The top of the call stack here is:

module.exports             (<...>\node_modules\documentjs\lib\generators\html\write\filename.js:2)
> 	var name = typeof docObject == "string" ? docObject : docObject.name;

urlTo                      (<...>\node_modules\documentjs\lib\generators\html\build\make_default_helpers.js:432)
>             return docsFilename(name, config);

program2                   (VM845:27)
>   buffer += escapeExpression(((stack1 = helpers.urlTo),stack1 ? stack1.call(depth0, depth0.name, options) : helperMissing.call(depth0, "urlTo", depth0.name, options)))

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\runtime.js:59)
>       return fn.apply(this, [context, options.data || data].concat(args));

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\base.js:100)
>         ret = ret + fn(context[i], { data: data });

program1                   (VM845:11)
>   stack1 = helpers.each.call(depth0, depth0.parents, {hash:{},inverse:self.noop,fn:self.programWithDepth(program2, data, depth0),data:data});

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\runtime.js:66)
>       return fn(context, options.data || data);

getActiveAndParents        (<...>\node_modules\documentjs\lib\generators\html\build\make_default_helpers.js:580)
> 			return options.fn({

(anonymous function)       (VM845:99)
>   if (stack1 = helpers.getActiveAndParents) { stack1 = stack1.call(depth0, options); }

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\runtime.js:30)
>       var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\compiler\compiler.js:1274)
>     return compiled.call(this, context, options);

invokePartial              (<...>\node_modules\handlebars\lib\handlebars\runtime.js:81)
>       partials[name] = Handlebars.compile(partial, {data: data !== undefined});

program3                   (VM844:20)
>   stack1 = self.invokePartial(partials['menu.mustache'], 'menu.mustache', depth0, helpers, partials, data);

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\runtime.js:66)
>       return fn(context, options.data || data);

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\base.js:125)
>     return options.inverse(this);

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\base.js:132)
>   return Handlebars.helpers['if'].call(this, context, {fn: options.inverse, inverse: options.fn});

(anonymous function)       (VM844:251)
>   stack1 = helpers.unless.call(depth0, depth0.hideSidebar, {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\runtime.js:30)
>       var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);

(anonymous function)       (<...>\node_modules\handlebars\lib\handlebars\compiler\compiler.js:1274)
>     return compiled.call(this, context, options);

renderer                   (<...>\node_modules\documentjs\lib\generators\html\build\get_renderer.js:22)
> 			var content = render(data);

module.exports             (<...>\node_modules\documentjs\lib\generators\html\write\doc_object.js:44)
> 		rendered = renderer(docObject);

module.exports             (<...>\node_modules\documentjs\lib\generators\html\write\doc_map.js:30)
> 			promises.push(writeDocObject(docObject, renderer, options, setCurrentDocObjectForHelpers));

So it's trying to render this getActiveAndParents section and makes a call to Handlebars.

The active argument to this is apparently a documentation object representing README.md and the parents argument is apparently an array with one element,

Object {name: undefined, body: "This is temporary content.  Create a undefined @page", type: "page", children: Array(1), glob: Object, …}

When this happens the urlTo is fed the .name property which is undefined, the typeof undefined is "undefined" which is not "string" so we try to access its .name, but this is attempting to lookup properties on undefined and generates the above TypeError.

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

No branches or pull requests

1 participant