hcengineering/platform · error

Unexpected line type: ${type}

Error message

Unexpected line type: ${type}

What it means

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.

Source

Thrown at plugins/diffview-resources/src/parser.ts:76

  const { header, oldStartLine, newStartLine } = block
  const lines = block.lines.map(mapLine)

  return { header, oldStartLine, newStartLine, lines }
}

function mapLine (line: D2HDiffLine): DiffLine {
  const { type, oldNumber, newNumber } = line
  const { prefix, content } = parseContentLine(line.content)

  switch (type) {
    case 'context':
      return { type: DiffLineType.CONTEXT, oldNumber, newNumber, prefix, content }
    case 'insert':
      return { type: DiffLineType.INSERT, oldNumber: undefined, newNumber, prefix, content }
    case 'delete':
      return { type: DiffLineType.DELETE, oldNumber, newNumber: undefined, prefix, content }
    default:
      throw new Error(`Unexpected line type: ${type}`)
  }
}

function mapFileDiffType (file: D2HDiffFile): DiffFileType {
  if (file.isNew === true) {
    return 'add'
  }
  if (file.isDeleted === true) {
    return 'delete'
  }
  if (file.isRename === true) {
    return 'rename'
  }
  if (file.isCopy === true) {
    return 'copy'
  }
  return 'modify'
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Update diffview-resources parser to map the new line type emitted by the diff producer
  2. Pin/align the diff producer library version with the parser's expected schema
  3. Sanitize or filter diff input to only known line types before parsing
  4. Extend the switch with a sensible default mapping (treat unknown as CONTEXT) if lossy handling is acceptable

Example fix

// before
default:
  throw new Error(`Unexpected line type: ${type}`)
// after
default:
  return { type: DiffLineType.CONTEXT, oldNumber, newNumber, prefix, content }
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN = ['context', 'insert', 'delete']
if (!KNOWN.includes(line.type)) {
  throw new Error(`Unsupported diff line type before parse: ${line.type}`)
}

Type guard

function isKnownLineType(t: string): t is 'context' | 'insert' | 'delete' {
  return t === 'context' || t === 'insert' || t === 'delete'
}

Try / catch

try {
  return mapLine(line, ...)
} catch (err) {
  if (err.message.startsWith('Unexpected line type')) {
    return { type: DiffLineType.CONTEXT, content: line.content } // degrade gracefully
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/3b9338e1fe585a4c. Report an issue: GitHub.