{"record":{"id":"ed178b9168b884b4","repo":"can1357/oh-my-pi","slug":"trusted-extension-requires-a-non-empty-non-flag","errorCode":null,"errorMessage":"--trusted-extension requires a non-empty, non-flag value","messagePattern":"--trusted-extension requires a non-empty, non-flag value","errorType":"validation","errorClass":"CliUsageError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/args.ts","lineNumber":318,"sourceCode":"\t\t\t// it so the post-extension reparse can decide whether to surface it\n\t\t\t// as a hard error. `--flag=value` already split `value` into the next\n\t\t\t// slot; the standard \"drop unconsumed equals value\" guard below\n\t\t\t// removes it so it does not leak into messages (issue #2459).\n\t\t\tresult.unrecognizedFlags.push(arg);\n\t\t}\n\t\t// Drop an unconsumed `--flag=value` value (e.g. a boolean flag): when no\n\t\t// branch advanced past the spliced token, remove it so it does not fall\n\t\t// through to a later iteration and become a positional message.\n\t\tif (equalsValueIndex !== -1 && i === flagIndex) {\n\t\t\targs.splice(equalsValueIndex, 1);\n\t\t}\n\t}\n\n\tconst swallowedTrustedFlag = [...(result.extensions ?? []), ...(result.hooks ?? [])].some(\n\t\tvalue => value === \"--trusted-extension\" || value.startsWith(\"--trusted-extension=\"),\n\t);\n\tif ((result.trustedExtensions?.length ?? 0) !== trustedFlagCount || swallowedTrustedFlag) {\n\t\tthrow new CliUsageError(\"--trusted-extension requires a non-empty, non-flag value\");\n\t}\n\tif (trustedFlagCount > 0 && ((result.extensions?.length ?? 0) > 0 || (result.hooks?.length ?? 0) > 0)) {\n\t\tthrow new CliUsageError(\"--trusted-extension cannot be combined with --extension, -e, or --hook\");\n\t}\n\tfor (const trustedPath of result.trustedExtensions ?? []) {\n\t\tif (trustedPath.length === 0) {\n\t\t\tthrow new CliUsageError(\"--trusted-extension requires a non-empty, non-flag value\");\n\t\t}\n\t\tif (!path.isAbsolute(trustedPath)) {\n\t\t\tthrow new CliUsageError(`--trusted-extension requires an absolute path: ${trustedPath}`);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/** Reject requested tool names absent from the fully discovered session registry. */\nexport function validateToolNames(requested: readonly string[] | undefined, known: readonly string[]): void {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/args.ts#L300-L336","documentation":"parseArgs counts occurrences of --trusted-extension and compares against the values actually collected. If the counts mismatch, or a value literally equals/starts with the flag itself (a value was swallowed as a flag), it throws this CliUsageError — meaning a --trusted-extension had no usable value attached.","triggerScenarios":"Running omp with a dangling `--trusted-extension` at the end of the command line, or `--trusted-extension --extension ...` where the next token looks like a flag, or `--trusted-extension=` with an empty value.","commonSituations":"Typing the flag with a leading-dash path (e.g. `-ext/mydir` interpreted as a flag), forgetting the value entirely, or using `=` form with nothing after it.","solutions":["Supply the path in the same token: --trusted-extension=/abs/path (or --trusted-extension /abs/path).","Ensure the value is non-empty and does not start with `--`.","Check shell quoting so the value is not split or consumed by another flag."],"exampleFix":"// before\nomp --trusted-extension\n// after\nomp --trusted-extension=/absolute/path/to/ext","handlingStrategy":"validation","validationCode":"// ensure every trusted-extension flag has a non-flag value attached\nconst argv = process.argv.slice(2);\nfor (let i = 0; i < argv.length; i++) {\n  if (argv[i] === \"--trusted-extension\" && (i + 1 >= argv.length || argv[i + 1].startsWith(\"--\"))) {\n    throw new Error(`--trusted-extension at position ${i} is missing a value`);\n  }\n}","typeGuard":"null","tryCatchPattern":"try {\n  const parsed = parseArgs(argv);\n} catch (err) {\n  if (err instanceof CliUsageError && err.message.includes(\"--trusted-extension\")) {\n    console.error(\"Usage: --trusted-extension=/absolute/path\");\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Prefer the --trusted-extension=/abs/path form so flag and value cannot separate.","Quote paths with spaces and avoid values starting with --.","Test new CLI wrappers with `omp --help` style dry runs before scripting them."],"tags":["cli","usage-error","argument-parsing","validation"],"backgroundTag":"missing-argument-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}