{"record":{"id":"baa372564edaca3a","repo":"heygen-com/hyperframes","slug":"context-fields-cannot-be-empty","errorCode":null,"errorMessage":"--context-fields cannot be empty","messagePattern":"--context-fields cannot be empty","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/preview.ts","lineNumber":483,"sourceCode":"  projectName: string;\n  projectDir: string;\n}): {\n  port: number;\n  projectName: string;\n  projectDir: string;\n  url: string;\n} {\n  return {\n    port: server.port,\n    projectName: server.projectName,\n    projectDir: server.projectDir,\n    url: previewBaseUrl(server.port, server.host),\n  };\n}\n\nfunction parseContextFields(value: string | undefined): ContextField[] {\n  if (value === undefined) return DEFAULT_CONTEXT_FIELDS;\n  if (!value.trim()) throw new Error(\"--context-fields cannot be empty\");\n  const allowed = new Set<ContextField>(DEFAULT_CONTEXT_FIELDS);\n  const fields = value\n    .split(\",\")\n    .map((field) => field.trim())\n    .filter(Boolean);\n  const invalid = fields.filter((field) => !allowed.has(field as ContextField));\n  if (invalid.length > 0) {\n    throw new Error(\n      `Unknown context field${invalid.length === 1 ? \"\" : \"s\"}: ${invalid.join(\", \")}`,\n    );\n  }\n  return [...new Set(fields)] as ContextField[];\n}\n\nfunction contextIncludes(fields: ContextField[], field: ContextField): boolean {\n  return fields.includes(field);\n}\n","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/cli/src/commands/preview.ts#L465-L501","documentation":"Thrown by parseContextFields in the preview command when --context-fields is passed but resolves to an empty/whitespace string. The flag accepts a comma-separated subset of context fields (server, selection, lint, capabilities); an explicitly empty value is rejected because it signals a malformed invocation rather than 'use defaults'. Passing nothing (omitting the flag) yields the default set and never throws.","triggerScenarios":"Invoking `hyperframes preview --context-fields \"\"` or `--context-fields \"   \"` (whitespace only). value is defined but value.trim() is empty at preview.ts:483. Omitting the flag passes undefined and returns DEFAULT_CONTEXT_FIELDS instead.","commonSituations":"A wrapper script or agent passes --context-fields with an env var that expanded to empty; a shell quoting bug drops the value; an editor/CI template hardcodes the flag with a placeholder that was never filled.","solutions":["Drop the flag entirely to use the defaults: `hyperframes preview`","Pass a valid comma-separated subset, e.g. `--context-fields server,lint`","If the value comes from an env var, guard it: only add the flag when $VAR is non-empty"],"exampleFix":"// before\nhyperframes preview --context-fields \"$CONTEXT_FIELDS\"\n// after (omit when empty)\nhyperframes preview ${CONTEXT_FIELDS:+--context-fields \"$CONTEXT_FIELDS\"}","handlingStrategy":"validation","validationCode":"function contextFieldsArg(v: string | undefined): string | undefined {\n  if (v === undefined) return undefined; // use defaults\n  if (!v.trim()) return undefined;       // drop empty -> defaults\n  return v;\n}\n// const arg = contextFieldsArg(process.env.HF_CONTEXT_FIELDS);","typeGuard":"function isContextField(v: string): v is \"server\" | \"selection\" | \"lint\" | \"capabilities\" {\n  return v === \"server\" || v === \"selection\" || v === \"lint\" || v === \"capabilities\";\n}","tryCatchPattern":null,"preventionTips":["Only forward --context-fields when the source value is non-empty","Prefer omitting the flag to accept the documented defaults","Validate against the four allowed fields before invoking the CLI"],"tags":["cli-input","preview","argument-validation"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}