{"record":{"id":"b37b5c67d748d0e4","repo":"jackwener/OpenCLI","slug":"folder-name-cannot-be-empty","errorCode":null,"errorMessage":"Folder name cannot be empty","messagePattern":"Folder name cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/quark/mkdir.js","lineNumber":20,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { DRIVE_API, apiPost, findFolder } from './utils.js';\ncli({\n    site: 'quark',\n    name: 'mkdir',\n    access: 'write',\n    description: 'Create a folder in your Quark Drive',\n    domain: 'pan.quark.cn',\n    strategy: Strategy.COOKIE,\n    defaultFormat: 'json',\n    args: [\n        { name: 'name', required: true, positional: true, help: 'Folder name' },\n        { name: 'parent', help: 'Parent folder path (resolved by name)' },\n        { name: 'parent-fid', help: 'Parent folder fid (use directly)' },\n    ],\n    func: async (page, kwargs) => {\n        const name = kwargs.name;\n        if (!name.trim())\n            throw new ArgumentError('Folder name cannot be empty');\n        if (kwargs.parent && kwargs['parent-fid']) {\n            throw new ArgumentError('Cannot use both --parent and --parent-fid');\n        }\n        const parentFid = kwargs['parent-fid']\n            ? kwargs['parent-fid']\n            : kwargs.parent\n                ? await findFolder(page, kwargs.parent)\n                : '0';\n        const data = await apiPost(page, `${DRIVE_API}?pr=ucpro&fr=pc`, {\n            pdir_fid: parentFid,\n            file_name: name,\n            dir_path: '',\n            dir_init_lock: false,\n        });\n        return { status: 'ok', fid: data.fid, name };\n    },\n});\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/quark/mkdir.js#L2-L38","documentation":"clis/quark/mkdir.js validates the --name argument before creating a folder on Quark drive. If the name is missing or only whitespace (name.trim() is empty), it throws ArgumentError('Folder name cannot be empty'). Quark's API would reject an empty name, so the CLI fails fast with a clear message.","triggerScenarios":"Running the quark mkdir command with no --name value, an empty string, or a name consisting solely of spaces, e.g. `quark mkdir --name \"  \"`.","commonSituations":"Shell variable holding the folder name was empty/unset; quoting mistake passing only spaces; scripting typo dropping the --name flag; CI pipeline interpolating an empty env var.","solutions":["Pass a non-empty --name value, e.g. `quark mkdir --name backups`.","In scripts, guard the variable before calling: [ -n \"$FOLDER\" ] || exit 1.","Check quoting so spaces in the name survive shell parsing.","If deriving the name dynamically, default it (e.g. use a date-stamped name) when the source is empty."],"exampleFix":"// before\nconst name = kwargs.name;\nif (!name.trim()) throw new ArgumentError('Folder name cannot be empty');\n// after (caller side)\nconst name = (kwargs.name ?? '').trim();\nif (!name) throw new ArgumentError('Folder name cannot be empty (got empty --name)');","handlingStrategy":"validation","validationCode":"const name = (process.argv[/* --name value */] ?? '').trim();\nif (!name) throw new Error('Provide a non-empty --name for quark mkdir');","typeGuard":"function isValidFolderName(n) {\n  return typeof n === 'string' && n.trim().length > 0;\n}","tryCatchPattern":"try {\n  await run(['quark', 'mkdir', '--name', name]);\n} catch (e) {\n  if (/Folder name cannot be empty/.test(String(e.message))) {\n    console.error('Fix the --name argument; it was empty or whitespace.');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Always trim and check CLI-supplied names before invoking","Guard shell variables: require non-empty env/params in scripts","Quote arguments so spaces and whitespace survive the shell","Fail fast in CI when interpolated names resolve to empty"],"tags":["argument-validation","quark","mkdir","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}