can1357/oh-my-pi · error · OmpTypeError

unterminated date literal in "${src}"

Error message

unterminated date literal in "${src}"

What it means

When tokenizing a type expression (e.g. for date-literal comparisons), a date literal opened with `d'` or `d"` was never closed by a matching quote before the end of the expression. The tokenizer throws instead of silently truncating.

Source

Thrown at packages/omptype/src/ir.ts:197

	| { t: "str"; v: string }
	| { t: "op"; v: string };

const SIMPLE_OPS = "|&()[]=?%,#";

function tokenize(src: string): Tok[] {
	const toks: Tok[] = [];
	let i = 0;
	const n = src.length;
	while (i < n) {
		const c = src[i];
		if (c === " " || c === "\t" || c === "\n" || c === "\r") {
			i++;
			continue;
		}
		if (c === "d" && (src[i + 1] === "'" || src[i + 1] === '"')) {
			const quote = src[i + 1];
			const end = src.indexOf(quote, i + 2);
			if (end < 0) throw new OmpTypeError(`unterminated date literal in "${src}"`);
			const source = src.slice(i + 2, end).trim();
			const value = /^\d+$/.test(source) ? new Date(Number(source)) : new Date(source);
			if (Number.isNaN(value.valueOf())) throw new OmpTypeError(`invalid date literal in "${src}"`);
			toks.push({ t: "date", v: value });
			i = end + 1;
			continue;
		}
		if (c === "'" || c === '"') {
			let j = i + 1;
			let value = "";
			for (; j < n && src[j] !== c; j++) {
				if (src[j] === "\\") {
					j++;
					if (j >= n) break;
				}
				value += src[j];
			}
			if (j >= n) throw new OmpTypeError(`unterminated string literal in "${src}"`);

View on GitHub (pinned to 9690622007)

Solutions

  1. Close the date literal with the same quote character used to open it: `d'2024-01-01'`.
  2. Check for quotes consumed by template-literal interpolation in generated expressions.
  3. Validate the expression string before passing it to the parser.

Example fix

// before
const t = type(`date > d'2024-01-01`);
// after
const t = type(`date > d'2024-01-01'`);
Defensive patterns

Strategy: validation

Validate before calling

if (!/^d['"][^'"]*['"]/.test(exprPart)) throw new Error("date literal must be d'...' or d\"...\"");

Try / catch

try {
  const t = new TypeExpression(src);
} catch (err) {
  if (err instanceof Error && err.message.includes("unterminated date literal")) {
    throw new Error(`Check quoting: ${err.message}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Type expressions like `d'2024-01-01` (missing closing quote) or `d"2024 > ` passed to a type parser constructed from `ir.ts` tokenization.

Common situations: Hand-written constraint strings with a dropped quote; string interpolation accidentally consuming the closing quote; copy-paste truncation.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/ad1fc6fa8c0de323. Report an issue: GitHub.