Skip to content

ampersand gen does not throw a proper error when specifying an invalid type #123

@coder13

Description

@coder13

This is the result of another error I found when I was trying to do ampersand gen collection and it was complaining

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.relative (path.js:1229:5)
    at module.exports (/home/caleb/.nvm/versions/node/v6.7.0/lib/node_modules/ampersand/lib/generate-template.js:54:31)
    at Object.<anonymous> (/home/caleb/.nvm/versions/node/v6.7.0/lib/node_modules/ampersand/bin/ampersand:59:5)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)

if (type === 'router') {
folderPath = path.join(config.approot, config.clientfolder);
filePath = path.join(folderPath, (fileName || 'router.js'));
} else if (type === 'model') {
if (!name) quit('please specify a name: ampersand gen model ' + chalk.magenta('${your model name}'));
folderPath = path.join(config.approot, config.clientfolder, config.modelfolder);
collectionPath = path.join(config.approot, config.clientfolder, config.collectionfolder);
filePath = path.join(folderPath, fileName);
collectionToModelPath = path.join(path.relative(collectionPath, folderPath), name).replace(/\\/g, '/');
} else if (type === 'view') {
if (!name) quit('please specify a name: ampersand gen view ' + chalk.magenta('${your view name}'));
folderPath = path.join(config.approot, config.clientfolder, config.viewfolder);
filePath = path.join(folderPath, fileName);
} else if (type === 'page') {
if (!name) quit('please specify a name: ampersand gen page ' + chalk.magenta('${your page name}'));
folderPath = path.join(config.approot, config.clientfolder, config.pagefolder);
filePath = path.join(folderPath, fileName);
} else if (type === 'form') {
if (!name) quit('please specify a path to the model: ampersand gen form ' + chalk.magenta('${path to model}'));
folderPath = path.join(config.approot, config.clientfolder, config.formsfolder);
filePath = path.join(folderPath, path.basename(fileName));
}

does not have an if case for collection even though the doc says that I can ampersand gen collection
thus
config.relPath = path.relative(process.cwd(), filePath);
complains about filePath being undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions