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: (name || "").replace is not a function #54

Closed
dannyrb opened this issue Nov 9, 2018 · 7 comments
Closed

TypeError: (name || "").replace is not a function #54

dannyrb opened this issue Nov 9, 2018 · 7 comments
Labels
bug docma-core v3 Fixed or implemented. To be released.

Comments

@dannyrb
Copy link

dannyrb commented Nov 9, 2018

image

I'm able to generate documentation if I limit it to a small subset of my source. When I expand it to all files, I get this error. No new output is generated. I'm unable to identify where/what is throwing this error.

Any/all help is appreciated; even if it's just some advice on how to debug docma 👍

@onury
Copy link
Owner

onury commented Nov 9, 2018

my eyes! how can you even read that output :/

:) I suspect a non-string argument got passed to cleanName() function; which tries some replace operation on it.

Can you replace cleanName() function in your local node_modules/jsdoc-x/src/lib/utils.js with the code below to see the cause:

function cleanName(name) {
    try {
        return (name || '').replace(/([^>]+>)?~?(.*)/, '$2')
            .replace(/^(module\.)?exports\./, '');
    } catch (err) {
        console.log('----> name:', name);
        console.log('----> type:', typeof name);
        throw err; // re-throw
    }
}

I think this can be fixed with:

function cleanName(name) {
    return String(name || '').replace(/([^>]+>)?~?(.*)/, '$2')
        .replace(/^(module\.)?exports\./, '');
}

@dannyrb
Copy link
Author

dannyrb commented Nov 9, 2018

Thanks for the quick response, @onury!

New information logged:

----> name: 48
----> type: number

When using your suggested fix, I don't see error output in PowerShell, but when serving the output I get a blank screen and a console error:

image

At some point, helper.getSymbolInfo is called with a kind, scope, and asButton of undefined. The symbol passed into getSymbolData looks like this:

$docmaLink: "?api#module:@public.waitForEnabledElementImageToLoad"
$kind: "constant"
$longname: "module:@public.waitForEnabledElementImageToLoad"
comment: "/**↵ * A promise that returns an EnabledElement who's image has loaded, or↵ * null if the provided element ceases being an enabledElement before an↵ * image has been loaded.↵ *↵ * @param {HTMLElement} element - An element that is an EnabledElement↵ * @returns {EnabledElement}↵ */"
description: "A promise that returns an EnabledElement who's image has loaded, or↵null if the provided element ceases being an enabledElement before an↵image has been loaded."
kind: "constant"
longname: "module:@public.waitForEnabledElementImageToLoad"
memberof: "module:@public"
meta:
code: {id: "astnode100069452", name: "exports.waitForEnabledElementImageToLoad", type: "VariableDeclaration"}
columnno: 0
filename: "wait.js"
lineno: 21
path: "C:\code\CornerstonePlayground\src\cornerstoneTools\src\util"
range: (2) [626, 1067]
__proto__: Object
name: "waitForEnabledElementImageToLoad"
params: Array(1)
0:
description: "An element that is an EnabledElement"
name: "element"
type:
names: ["HTMLElement"]
...
returns: Array(1)
0:
type:
names: ["EnabledElement"]
...

Because it has a kind of constant, it is not handled by any of the if statements in getSymbolData and helper.getSymbolInfo is called with 0 arguments passed. helper.getSymbolInfo looks like it will always throw if kind is empty, so helper.getSymbolInfo should never be called without arguments?

If it helps, here is what the original code for that module looks like:

import external from './../externalModules.js';

/**
 * Waits a set amount of time, then resolves. Can be chained off of to delay
 * next call in promise chain.
 *
 * @exports @public @function
 * @param {number} ms - number in ms to wait
 * @returns {Promise}
 */
export const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

/**
 * A promise that returns an EnabledElement who's image has loaded, or
 * null if the provided element ceases being an enabledElement before an
 * image has been loaded.
 *
 * @param {HTMLElement} element - An element that is an EnabledElement
 * @returns {EnabledElement}
 */
export const waitForEnabledElementImageToLoad = (element) => {
  try {
    const enabledElement = external.cornerstone.getEnabledElement(element);

    if (!enabledElement.image) {
      return wait(250).then(() => waitForEnabledElementImageToLoad(element));
    }

    // EnabledElement's image is loaded.
    return enabledElement;
  } catch (ex) {
    // Is no longer, or never was an enabled element, stop polling
    return null;
  }
};

export default wait;

@dannyrb
Copy link
Author

dannyrb commented Nov 9, 2018

Looking closer at existing issues, I think we've identified one new issue, and stumbled upon a second. The second issue appears to be a duplicate of: #41

Update: I was able to get documentation generation and served by doing the following:

Everything appears to be working beautifully now 👍 I would be open to contributing changes that address these issues if you are willing to review a PR? Any guidance you have would be appreciated.

@onury
Copy link
Owner

onury commented Nov 10, 2018

Thanks. I'm fixing this with some other revisions. I'll let you know.

@onury
Copy link
Owner

onury commented Nov 11, 2018

This is fixed now.
I'm waiting for users on other issues before I release new version.

@onury onury added Fixed or implemented. To be released. v3 labels Nov 13, 2018
@onury
Copy link
Owner

onury commented Nov 18, 2018

Fixed with Docma v3.0.0.

@onury onury closed this as completed Nov 18, 2018
@warpdesign
Copy link
Contributor

I am migrating an old template from v1 to v2 and stumbled upon this bug. Is there a workaround for this other than patching jsdoc-x?

Note: I am planning to move to the latest v3 version later but one step at a time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug docma-core v3 Fixed or implemented. To be released.
Projects
None yet
Development

No branches or pull requests

3 participants