{"record":{"id":"d4005d1166e6d910","repo":"can1357/oh-my-pi","slug":"line-linenum-expected-a-line-number-such-as","errorCode":null,"errorMessage":"line ${lineNum}: expected a line number such as ${describeAnchorExamples(\"119\")}; got ${JSON.stringify(raw)}. Use ${HL_FILE_PREFIX}PATH${HL_FILE_HASH_SEP}hash${HL_FILE_SUFFIX} from your latest read for file-version binding.","messagePattern":"line (.+?): expected a line number such as (.+?); got (.+?)\\. Use (.+?)PATH(.+?)hash(.+?) from your latest read for file-version binding\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/hashline/src/tokenizer.ts","lineNumber":144,"sourceCode":"\tlet lineNumber = 0;\n\tlet nextIndex = index;\n\twhile (nextIndex < end) {\n\t\tconst code = line.charCodeAt(nextIndex);\n\t\tif (!isDigitCode(code)) break;\n\t\tlineNumber = lineNumber * 10 + (code - CHAR_ZERO);\n\t\tif (!Number.isSafeInteger(lineNumber)) return null;\n\t\tnextIndex++;\n\t}\n\treturn { line: lineNumber, nextIndex };\n}\n\n/** Parse a bare line-number anchor. Throws on malformed input. */\nexport function parseLid(raw: string, lineNum: number): Anchor {\n\tconst end = trimEndIndex(raw);\n\tconst numberStart = skipWhitespace(raw, 0, end);\n\tconst number = scanLineNumber(raw, numberStart, end);\n\tif (number === null || skipWhitespace(raw, number.nextIndex, end) !== end) {\n\t\tthrow new Error(\n\t\t\t`line ${lineNum}: expected a line number such as ${describeAnchorExamples(\"119\")}; ` +\n\t\t\t\t`got ${JSON.stringify(raw)}. Use ${HL_FILE_PREFIX}PATH${HL_FILE_HASH_SEP}hash${HL_FILE_SUFFIX} from your latest read for file-version binding.`,\n\t\t);\n\t}\n\treturn { line: number.line };\n}\n\ninterface RangeScan {\n\trange: ParsedRange;\n\tnextIndex: number;\n\thadSeparator: boolean;\n}\n\n/**\n * Range separator scanner. Canonical input is `.=`, while parsing remains\n * deliberately lenient for model output: `-`, `=`, `.`, `..`, `…`, mixed\n * runs, and whitespace-only separators all recover to the same range.\n */","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/hashline/src/tokenizer.ts#L126-L162","documentation":"parseLid parses a bare line-number anchor (e.g. \"119\") in the hashline tokenizer and throws this error when the input is not a well-formed line number (no parsable number, or trailing garbage after the number). It is a fail-fast guard: malformed anchor strings would otherwise silently resolve to the wrong line. The message also reminds the caller that PATH#hash anchors exist for file-version binding.","triggerScenarios":"Calling parseLid with a string like \"abc\", \"12x\", \"\", \"  \", or \"119 #comment\" — any raw anchor that fails scanLineNumber or has non-whitespace trailing characters.","commonSituations":"An LLM or script emits a malformed line reference (e.g. \"L119\", \"119-120\", or a range/prefixed form) into an anchor parser; tooling that concatenates a suffix onto the number; copy-pasted anchors with trailing text.","solutions":["Correct the anchor to a bare integer line number, e.g. \"119\".","Trim whitespace and remove any trailing annotations from the raw string before calling parseLid.","If you need a file-version-bound reference, use the PATH#hash anchor form (HL_FILE_PREFIX PATH HL_FILE_HASH_SEP hash HL_FILE_SUFFIX) instead of a bare lid.","If you must accept looser formats, sanitize/normalize the input (strip prefixes like 'L', extract the leading integer) before parsing."],"exampleFix":"// before\nparseLid(\"L119\", 3) // throws\n// after\nparseLid(\"119\", 3) // => { line: 119 }","handlingStrategy":"validation","validationCode":"const ANCHOR_RE = /^\\d+$/;\nif (!ANCHOR_RE.test(raw.trim())) throw new Error(`bad lid: ${JSON.stringify(raw)}`);\nconst anchor = parseLid(raw.trim(), lineNum);","typeGuard":"function isValidLid(raw: string): boolean {\n\tconst t = raw.trim();\n\tconst n = Number.parseInt(t, 10);\n\treturn Number.isInteger(n) && n > 0 && t === String(n);\n}","tryCatchPattern":"let anchor;\ntry {\n\tanchor = parseLid(raw, lineNum);\n} catch (err) {\n\tthrow new UsageError(`Anchor must be a bare line number like '119', got ${raw}`);\n}","preventionTips":["Emit anchors programmatically from parsed read results instead of hand-building strings.","Strip common prefixes like 'L' and ranges before calling the parser.","Validate with /^\\d+$/ before calling parseLid.","Never append comments or suffixes to a bare line-number anchor."],"tags":["parser","validation","input-format"],"backgroundTag":"invalid-anchor-format","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}