{"record":{"id":"f467a857744f7152","repo":"Hmbown/CodeWhale","slug":"missing-core-module","errorCode":null,"errorMessage":"Missing core module","messagePattern":"Missing core module","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":2532,"sourceCode":"    trace.append(records);\n    return trace.snapshot();\n}\n/** The journal owns request state until a matching terminal receipt. A live\n * driver may confirm that state only while its cursor-checked stream is healthy.\n * Ordinary open tool spans remain unknown-duration; no execution is inferred. */\nfunction observeRuntimeRequests(trace, observedThrough) {\n    const origin = Date.parse(trace.originTime ?? '');\n    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n        || !Number.isFinite(observedThrough))\n        throw new Error('Invalid Runtime observation horizon.');\n    const at = observedThrough - origin;\n    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime\n        ? { ...e, endTime: at, openEnded: false } : e);\n    return { ...trace, events, duration: Math.max(trace.duration, at) };\n}\n\n};\nfunction load(id){id=id.replace(/^\\.\\//,'').replace(/\\.js$/,'');if(cache[id])return cache[id];if(!factories[id])throw Error('Missing core module');const e=cache[id]={};factories[id](e,load);return e;}\nglobal.PetNative=load('pet-native').PetNative;\n})(globalThis);\n","sourceCodeStart":2514,"sourceCodeEnd":2535,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L2514-L2535","documentation":"pet-native.js embeds a tiny CommonJS-style module loader at the bottom of its IIFE: `load(id)` normalizes the id, checks a `factories` registry, and throws Error('Missing core module') when the requested id was never registered in `factories`. This is an internal wiring guard — only module ids statically listed in the bundle's factories map are loadable, and the entry point does `global.PetNative=load('pet-native').PetNative`.","triggerScenarios":"The loader is called with an id that has no entry in the `factories` object: a require-style call such as load('helper') where the helper module was renamed, its `.js` suffix handling stripped differently (e.g. load('./helper.js') after the regex strips it — but a call passing 'subdir/helper' when factories only registers 'helper'), or a refactor removed a module's factory registration while another module still loads it. Also triggered if the bundle was partially generated/concatenated, dropping one module's factory block.","commonSituations":"A developer renames or splits a module in the pet-native bundle but forgets to register the new factory under the expected key; a build step that assembles modules out of order or drops one; a typo in the id string passed to load() (e.g. 'pet-native-core' vs 'pet-native'); tree-shaking or minification removing what looks like dead factory code.","solutions":["Compare the id passed to load() (or the failing internal require) against the keys actually registered in the `factories` object in pet-native.js; fix the id or add the missing factory.","If a module was renamed/split, update all load()/require call sites to the new id and ensure the factory function `factories[id](e,load)` signature matches.","If a build/concat step assembles this bundle, verify it emits every module's factory block and that the entry `load('pet-native')` id matches a registered key.","Add a console.log(Object.keys(factories)) before the throw while debugging to see which ids exist at runtime."],"exampleFix":"// before\nfunction load(id){id=id.replace(/^\\.\\//,'').replace(/\\.js$/,'');if(cache[id])return cache[id];if(!factories[id])throw Error('Missing core module');...}\nconst settings = load('./config'); // factories has 'config-core', not 'config'\n// after\nconst settings = load('./config-core'); // id matches a registered factory key\n// (or register the missing factory:) factories['config'] = function(exports, require){ ... };","handlingStrategy":"type-guard","validationCode":"// Callers of the loader / wrapper API:\nfunction canLoad(id) {\n  const norm = id.replace(/^\\.\\//, '').replace(/\\.js$/, '');\n  return typeof globalThis.PetNative !== 'undefined' && norm.length > 0;\n}\n// For maintainers editing the bundle: assert registration at startup\nif (typeof factories['pet-native'] !== 'function') throw new Error('pet-native factory missing');","typeGuard":"function isLoadedModule(id) {\n  return typeof id === 'string' && typeof cache[id.replace(/^\\.\\//, '').replace(/\\.js$/, '')] !== 'undefined';\n}","tryCatchPattern":"try {\n  const mod = load(id);\n  use(mod);\n} catch (err) {\n  if (err.message === 'Missing core module') {\n    console.error(`Module \"${id}\" is not registered; available: ${Object.keys(factories)}`);\n  } else throw err;\n}","preventionTips":["Keep module ids and factory registrations in one table and derive load() calls from it.","When renaming/splitting a module, grep the bundle for all load()/require sites of the old id.","Add a startup smoke test that loads every registered module id.","If a build step assembles factories, verify all blocks are emitted with a key-count check."],"tags":["module-loader","javascript","bundling","internal"],"backgroundTag":"missing-dependency","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}