coding-horror/basic-computer-games · error · Error
Unknown file-type found: ${file}
Error message
Unknown file-type found: ${file} What it means
Thrown by createFileLink() in the build-index.js index generator when a file path passed to it ends with neither '.html' nor '.mjs'. The generator only knows how to render links for those two file kinds, so any other extension is treated as a programmer error. In practice findJSFilesInFolder() upstream filters to only .html/.mjs, so this branch is a defensive guard that is effectively unreachable through the normal pipeline unless a new extension is added to the filter without updating the link builder.
Source
Thrown at 00_Utilities/build-index.js:33
const JAVASCRIPT_FOLDER = 'javascript';
const IGNORE_FOLDERS_START_WITH = ['.', '00_', 'buildJvm', 'Sudoku'];
const IGNORE_FILES = [
// "84 Super Star Trek" has it's own node/js implementation (using xterm)
'cli.mjs', 'superstartrek.mjs'
];
function createGameLinks(game) {
const creatFileLink = (file, name = path.basename(file)) => {
if (file.endsWith('.html')) {
return `
<li><a href="${file}">${name.replace('.html', '')}</a></li>
`;
} else if (file.endsWith('.mjs')) {
return `
<li><a href="./00_Common/javascript/WebTerminal/terminal.html#${file}">${name.replace('.mjs', '')} (node.js)</a></li>
`;
} else {
throw new Error(`Unknown file-type found: ${file}`);
}
}
if (game.files.length > 1) {
const entries = game.files.map(file => {
return creatFileLink(file);
});
return `
<li>
<span>${game.name}</span>
<ul>${entries.map(e => `\t\t\t${e}`).join('\n')}</ul>
</li>
`;
} else {
return creatFileLink(game.files[0], game.name);
}
}
View on GitHub (pinned to 5301155192)
Solutions
- Add a matching else-if branch in createFileLink for the new extension before the final else, mirroring the .html/.mjs branches.
- If the new type should be ignored, add it to IGNORE_FILES at line 17 instead of collecting it.
- Revert the upstream filter change so only .html/.mjs are collected.
Example fix
// before
const mjsFiles = files.filter(file => file.endsWith('.mjs'));
const entries = [...htmlFiles, ...mjsFiles].filter(...);
// createFileLink has no case for .js -> throws
// after (add branch)
} else if (file.endsWith('.js')) {
return `\n\t\t\t<li><a href="./00_Common/javascript/WebTerminal/terminal.html#${file}">${name.replace('.js','')} (node.js)</a></li>\n\t\t`;
} Defensive patterns
Strategy: validation
Validate before calling
// Validate game.files before calling createGameLinks
function assertKnownFiles(files) {
const bad = files.filter(f => !f.endsWith('.html') && !f.endsWith('.mjs'));
if (bad.length) throw new Error(`Unsupported extensions: ${bad.join(', ')}`);
}
// in createGameLinks:
assertKnownFiles(game.files); Type guard
// Node has no static type guard; runtime check instead
const isLinkableFile = (f) => typeof f === 'string' && (f.endsWith('.html') || f.endsWith('.mjs')); Try / catch
// main() already wraps findJSFilesInFolder in try/catch (build-index.js:134-139);
// wrap createIndexHtml similarly if createGameLinks can throw:
try { const html = createIndexHtml(TITLE, games); }
catch (e) { console.error('Index build failed:', e.message); process.exit(1); } Prevention
- When adding a new supported extension to findJSFilesInFolder's filter, add the matching branch in createFileLink in the same commit.
- Keep a single constant (e.g. SUPPORTED_EXT) referenced by both the filter and the link builder so they cannot drift.
- Add a unit test asserting createFileLink handles every extension the filter collects.
When it happens
Trigger: Calling createGameLinks(game) where game.files contains an entry whose extension is not .html or .mjs; e.g. someone edits findJSFilesInFolder to also collect '.js' files but forgets to teach createFileLink how to link them, or invokes createFileLink directly with an arbitrary path.
Common situations: Extending the index builder to support a new file type (e.g. plain .js or .ts web ports) and adding the extension to the filter array at build-index.js:100-101 without adding a matching branch in createFileLink at line 23-34.
Related errors
- Game "${folder}" is missing a javascript folder
- Game "${folder}" is missing a HTML or node.js file in the fo
AI-assisted analysis of coding-horror/basic-computer-games@5301155192 (2026-08-13).
Data as JSON: /api/errors/be83482cd959ecfc.
Report an issue: GitHub.