{"record":{"id":"3b9338e1fe585a4c","repo":"hcengineering/platform","slug":"unexpected-line-type-type","errorCode":null,"errorMessage":"Unexpected line type: ${type}","messagePattern":"Unexpected line type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/diffview-resources/src/parser.ts","lineNumber":76,"sourceCode":"  const { header, oldStartLine, newStartLine } = block\n  const lines = block.lines.map(mapLine)\n\n  return { header, oldStartLine, newStartLine, lines }\n}\n\nfunction mapLine (line: D2HDiffLine): DiffLine {\n  const { type, oldNumber, newNumber } = line\n  const { prefix, content } = parseContentLine(line.content)\n\n  switch (type) {\n    case 'context':\n      return { type: DiffLineType.CONTEXT, oldNumber, newNumber, prefix, content }\n    case 'insert':\n      return { type: DiffLineType.INSERT, oldNumber: undefined, newNumber, prefix, content }\n    case 'delete':\n      return { type: DiffLineType.DELETE, oldNumber, newNumber: undefined, prefix, content }\n    default:\n      throw new Error(`Unexpected line type: ${type}`)\n  }\n}\n\nfunction mapFileDiffType (file: D2HDiffFile): DiffFileType {\n  if (file.isNew === true) {\n    return 'add'\n  }\n  if (file.isDeleted === true) {\n    return 'delete'\n  }\n  if (file.isRename === true) {\n    return 'rename'\n  }\n  if (file.isCopy === true) {\n    return 'copy'\n  }\n  return 'modify'\n}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/diffview-resources/src/parser.ts#L58-L94","documentation":"mapLine converts D2H diff line types ('context', 'insert', 'delete') into DiffLineType values and throws on any unrecognized type string. This is a defensive exhaustiveness check in the diffview parser for unexpected upstream data.","triggerScenarios":"Parsing a diff whose hunk line type is not one of context/insert/delete, e.g. a new type emitted by a changed diff producer, corrupted diff data, or parser/producer version mismatch.","commonSituations":"Upstream diff library upgraded and emitting new line type values; malformed or hand-edited diff payloads fed to the parser; binary or metadata lines misclassified as diff lines.","solutions":["Update diffview-resources parser to map the new line type emitted by the diff producer","Pin/align the diff producer library version with the parser's expected schema","Sanitize or filter diff input to only known line types before parsing","Extend the switch with a sensible default mapping (treat unknown as CONTEXT) if lossy handling is acceptable"],"exampleFix":"// before\ndefault:\n  throw new Error(`Unexpected line type: ${type}`)\n// after\ndefault:\n  return { type: DiffLineType.CONTEXT, oldNumber, newNumber, prefix, content }","handlingStrategy":"validation","validationCode":"const KNOWN = ['context', 'insert', 'delete']\nif (!KNOWN.includes(line.type)) {\n  throw new Error(`Unsupported diff line type before parse: ${line.type}`)\n}","typeGuard":"function isKnownLineType(t: string): t is 'context' | 'insert' | 'delete' {\n  return t === 'context' || t === 'insert' || t === 'delete'\n}","tryCatchPattern":"try {\n  return mapLine(line, ...)\n} catch (err) {\n  if (err.message.startsWith('Unexpected line type')) {\n    return { type: DiffLineType.CONTEXT, content: line.content } // degrade gracefully\n  }\n  throw err\n}","preventionTips":["Keep the parser in sync with the diff producer library version","Validate diff payloads against the expected schema before parsing","Add a regression test for every new upstream line type","Filter out non-diff lines before mapping"],"tags":["diff","parser","exhaustiveness"],"backgroundTag":"unexpected-enum-value","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}