can1357/oh-my-pi · error
unknown key ${rest}
Error message
unknown key ${rest} What it means
encodeChord() accepts either a SPECIAL_KEYS name or a single character as the base key. If the remaining token (after modifiers) is neither — e.g. multi-character words not in the table — it throws `unknown key ${rest}`.
Source
Thrown at packages/tui/src/debug-server.ts:147
rest = rest.slice(2);
}
if (/^S-/i.test(rest)) {
shift = true;
rest = rest.slice(2);
}
if (rest.length === 0 || /^(?:C-|A-|M-|S-)/i.test(rest)) throw new Error(`invalid key token ${token}`);
const name = rest.toLowerCase();
const special = SPECIAL_KEYS[name];
if (special !== undefined) {
if (ctrl && name === "space") return alt ? "\x1b\x00" : "\x00";
if (ctrl && name === "backspace") return alt ? "\x1b\x08" : "\x08";
const modifier = 1 + (shift ? 1 : 0) + (alt ? 2 : 0) + (ctrl ? 4 : 0);
let encoded = modifiedSpecial(special, modifier);
if (alt && encoded === special) encoded = `\x1b${encoded}`;
return encoded;
}
if (Array.from(rest).length !== 1) throw new Error(`unknown key ${rest}`);
let character = rest;
if (shift && /^[a-z]$/i.test(character)) character = character.toUpperCase();
if (ctrl) character = ctrlCharacter(character);
return alt ? `\x1b${character}` : character;
}
function parseKeyTokens(source: string): { sequences: string[]; events: number } {
let offset = 0;
const sequences: string[] = [];
let events = 0;
while (offset < source.length) {
while (/\s/.test(source[offset] ?? "")) offset++;
if (offset >= source.length) break;
const quote = source[offset];
if (quote === "'" || quote === '"') {
offset++;
let literal = "";
while (offset < source.length && source[offset] !== quote) {View on GitHub (pinned to 9690622007)
Solutions
- Use a key name listed in SPECIAL_KEYS (e.g. "enter", "tab", "escape")
- For literal text, use the quoted-literal syntax of the key sequence parser
- Fix typos in the key name
Example fix
// before
encodeChord("pageup") // if not in SPECIAL_KEYS
// after
encodeChord("page-up") // or the exact SPECIAL_KEYS spelling Defensive patterns
Strategy: validation
Validate before calling
function isKnownKey(name: string): boolean {
return name.length === 1 || name.toLowerCase() in SPECIAL_KEYS;
} Try / catch
try {
seq = encodeChord(token);
} catch (err) {
if (err instanceof Error && err.message.startsWith("unknown key")) {
logger.warn("unknown key name", { token });
continue;
}
throw err;
} Prevention
- Consult SPECIAL_KEYS for exact key spellings before writing sequences
- Quote multi-character literals instead of passing them as bare tokens
- Add a smoke test that encodes every key name your scripts use
When it happens
Trigger: Tokens like "foo", "enter-key", "page-up" if not present in SPECIAL_KEYS, or multi-char literals passed as bare tokens instead of quoted literals.
Common situations: Misspelled special key names ("backspace" vs "backpace"); using platform-specific key names not in SPECIAL_KEYS; forgetting to quote literal strings in the key sequence.
Related errors
- invalid key token ${token}
- cannot encode ctrl chord ${character}
- unterminated quoted key literal
- Replacement text is not valid UTF-8: {err}
- V2 compaction stream parse failed: ${err instanceof Error ?
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/83d6477e0e3c3f6b.
Report an issue: GitHub.