{"record":{"id":"76574759637e3962","repo":"heygen-com/hyperframes","slug":"invalid-color-grading-for-cell-cell-label","errorCode":null,"errorMessage":"Invalid color grading for cell \"${cell.label}\"","messagePattern":"Invalid color grading for cell \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/grade-compare.ts","lineNumber":178,"sourceCode":"  );\n  return { cells: cells.slice(0, MAX_CANDIDATE_CELLS), truncated: true, total };\n}\n\nexport function buildGradeCompareSuccessPayload(\n  sheet: string,\n  cells: number,\n  capResult: CandidateCellCapResult,\n): GradeCompareSuccessPayload {\n  if (!capResult.truncated) {\n    return { ok: true, sheet, cells };\n  }\n  return { ok: true, sheet, cells, truncated: true, total: capResult.total };\n}\n\nfunction serializedGradingForCell(cell: GradeCompareCell): string {\n  const normalized = normalizeHfColorGrading(cell.grading);\n  if (!normalized) {\n    throw new Error(`Invalid color grading for cell \"${cell.label}\"`);\n  }\n  return serializeHfColorGrading(normalized);\n}\n\nfunction lutSrcFromGrading(grading: unknown): string | null {\n  if (!isRecord(grading) || !hasOwn(grading, \"lut\")) return null;\n  const lut = grading.lut;\n  if (typeof lut === \"string\" && lut.trim()) return lut.trim();\n  if (!isRecord(lut)) return null;\n  const src = lut.src;\n  return typeof src === \"string\" && src.trim() ? src.trim() : null;\n}\n\nfunction rewriteGradingLutSrc(grading: unknown, src: string): unknown {\n  if (!isRecord(grading) || !hasOwn(grading, \"lut\")) return grading;\n  const lut = grading.lut;\n  const next = cloneRecord(grading);\n  if (typeof lut === \"string\") {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/cli/src/commands/grade-compare.ts#L160-L196","documentation":"Thrown by serializedGradingForCell() during buildGradeCompareHtml — the second normalization pass that serializes a cell's grading into the data-hf-color-grading attribute. It uses the exact same normalizeHfColorGrading as validateCell, so by the time a cell reaches here it should already be valid. Hitting it means a cell was constructed without validateCell, or its grading was mutated to an invalid shape between validation and serialization (e.g. by rewriteGradingLutSrc).","triggerScenarios":"A programmatic caller building GradeCompareCell objects directly and bypassing validateCell/parseGradesFile/resolveLutCells; a LUT-rewrite path that produced a malformed grading object; a cell whose grading is an object with enabled:false introduced after validation.","commonSituations":"Using the exported prepareGradeCompareTempProject with hand-built cells; a future grading-rewrite helper that does not preserve the valid shape.","solutions":["Always construct cells through validateCell, parseGradesFile, or resolveLutCells","If mutating grading before serialization, re-run validateCell afterward","Unit-test that each cell round-trips through normalizeHfColorGrading"],"exampleFix":"// before: hand-built cell bypasses validation\nconst cell = { label: \"warm\", grading: { enabled: false } };\n// after: construct via validateCell so invalid shapes fail early\nimport { normalizeHfColorGrading } from \"@hyperframes/core\";\nconst ok = normalizeHfColorGrading(cell.grading);\nif (!ok) throw new Error(`invalid grading for ${cell.label}`);","handlingStrategy":"type-guard","validationCode":"import { normalizeHfColorGrading } from '@hyperframes/core';\n// Always construct cells through validateCell so invalid shapes fail at the boundary,\n// and re-validate after any mutation (e.g. LUT src rewrite).\nconst normalized = normalizeHfColorGrading(cell.grading);\nif (!normalized) throw new Error(`invalid grading for ${cell.label}`);","typeGuard":"import { normalizeHfColorGrading } from '@hyperframes/core';\nfunction isValidGrading(grading: unknown): boolean {\n  return normalizeHfColorGrading(grading) !== null;\n}","tryCatchPattern":null,"preventionTips":["Never build GradeCompareCell objects by hand — go through validateCell/parseGradesFile/resolveLutCells","After rewriting a grading (e.g. LUT src), re-run normalizeHfColorGrading","Unit-test that each cell round-trips through normalize then serialize"],"tags":["color-grading","validation","grade-compare","serialize"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}