{"record":{"id":"0d8dafc528daca4d","repo":"mastra-ai/mastra","slug":"missing-value-for-flag","errorCode":null,"errorMessage":"Missing value for ${flag}","messagePattern":"Missing value for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/tui/src/main.ts","lineNumber":296,"sourceCode":"\n  const dir = args[1];\n  if (!dir) {\n    process.stderr.write('Usage: mastracode plugin scaffold <dir> [--id acme.foo] [--name \"Foo Tools\"]\\n');\n    process.exit(1);\n  }\n\n  const id = readFlag(args, '--id');\n  const name = readFlag(args, '--name');\n  const targetDir = scaffoldPlugin(dir, { ...(id ? { id } : {}), ...(name ? { name } : {}) });\n  process.stdout.write(`${formatScaffoldSuccess(targetDir)}\\n`);\n}\n\nfunction readFlag(args: string[], flag: string): string | undefined {\n  const index = args.indexOf(flag);\n  if (index === -1) return undefined;\n  const value = args[index + 1];\n  if (!value || value.startsWith('--')) {\n    throw new Error(`Missing value for ${flag}`);\n  }\n  return value;\n}\n\nconst handleFatalError = createOneShotFatalErrorHandler((error: unknown): void => {\n  // Always write to real stderr, even if console.error was overridden\n  const write = (msg: string) => {\n    try {\n      process.stderr.write(msg + '\\n');\n    } catch {}\n  };\n\n  if (hasEconnrefused(error)) {\n    const settings = loadSettings();\n    const connStr = settings.storage?.pg?.connectionString;\n    const target = connStr ?? 'localhost:5432';\n    write(\n      `\\nFailed to connect to PostgreSQL at ${target}.` +","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/tui/src/main.ts#L278-L314","documentation":"readFlag is a tiny CLI arg parser in the TUI entrypoint: when a --flag is present but the following token is missing or is itself another flag (starts with '--'), it throws 'Missing value for <flag>' instead of silently treating the flag as undefined.","triggerScenarios":"Invoking the TUI like `mastracode --model` (nothing after) or `mastracode --name --thread abc` where the next token is another flag, so the intended value was never supplied.","commonSituations":"Truncated copy-paste of a launch command; shell alias dropping the value; forgetting that a value starting with '-' needs quoting or an '=' form; scripting that conditionally appends the value and emits nothing.","solutions":["Pass the value right after the flag: `mastracode --model openai/gpt-4o`","Quote values that start with dashes: `--name \"--special\"`","Fix the script/alias so the value token is actually emitted"],"exampleFix":"// before\nmastracode --model --thread t1\n// after\nmastracode --model openai/gpt-4o --thread t1","handlingStrategy":"validation","validationCode":"function requireFlagValue(args: string[], flag: string): string {\n  const i = args.indexOf(flag);\n  if (i === -1) throw new Error(`${flag} is required`);\n  const v = args[i + 1];\n  if (!v || v.startsWith('--')) throw new Error(`Missing value for ${flag}`);\n  return v;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const model = readFlag(process.argv.slice(2), '--model');\n} catch (e) {\n  console.error((e as Error).message, '\\nUsage: mastracode --model <model-id>');\n  process.exit(1);\n}","preventionTips":["Always pass the value immediately after the flag with no missing tokens","Quote values that begin with a dash","Audit shell aliases/scripts so the value token is always emitted","Prefer the `--flag=value` style when writing your own launch wrappers"],"tags":["cli","arguments","parsing","tui"],"backgroundTag":"missing-cli-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}