{"record":{"id":"433abc4ad9256003","repo":"thedotmack/claude-mem","slug":"no-mode-loaded-call-loadmode-first","errorCode":null,"errorMessage":"No mode loaded. Call loadMode() first.","messagePattern":"No mode loaded\\. Call loadMode\\(\\) first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/domain/ModeManager.ts","lineNumber":178,"sourceCode":"    }\n\n    const mergedMode = this.deepMerge(parentMode, overrideConfig);\n    this.activeMode = mergedMode;\n    this.activeModeId = modeId;\n\n    logger.debug('SYSTEM', `Loaded mode with inheritance: ${mergedMode.name} (${modeId} = ${parentId} + ${overrideId})`, undefined, {\n      parent: parentId,\n      override: overrideId,\n      types: mergedMode.observation_types.map(t => t.id),\n      concepts: mergedMode.observation_concepts.map(c => c.id)\n    });\n\n    return mergedMode;\n  }\n\n  getActiveMode(): ModeConfig {\n    if (!this.activeMode) {\n      throw new Error('No mode loaded. Call loadMode() first.');\n    }\n    return this.activeMode;\n  }\n\n  getActiveModeId(): string {\n    if (!this.activeModeId) {\n      throw new Error('No mode loaded. Call loadMode() first.');\n    }\n    return this.activeModeId;\n  }\n\n  getObservationTypes(): ObservationType[] {\n    return this.getActiveMode().observation_types;\n  }\n\n  getTypeIcon(typeId: string): string {\n    const type = this.getObservationTypes().find(t => t.id === typeId);\n    return type?.emoji || '📝';","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/domain/ModeManager.ts#L160-L196","documentation":"getActiveMode() returns the currently merged ModeConfig, but the manager is a stateful object that requires loadMode() to have been called first. If activeMode is still unset, it throws this error. It is a lifecycle/initialization-order guard, not a data problem.","triggerScenarios":"Calling getActiveMode() (directly or via getObservationTypes()) on a fresh ModeManager instance before any successful loadMode() call, or after loadMode() threw and left no active mode.","commonSituations":"Constructor-time code reading observation types before mode load completes; async initialization race where getObservationTypes() runs before await loadMode() resolves; swallowing the loadMode error earlier and continuing.","solutions":["Call `await modeManager.loadMode(...)` before any getActiveMode()/getObservationTypes() call.","Check why the earlier loadMode() failed (fix that error first) — active mode stays unset.","Guard call sites: only query the manager after initialization completes (e.g. an `initialized` flag/promise).","If modes are optional in your context, wrap access in try-catch and use a default config."],"exampleFix":"// before\nconst mm = new ModeManager(dirs);\nconst types = mm.getObservationTypes(); // throws\n// after\nconst mm = new ModeManager(dirs);\nawait mm.loadMode('code');\nconst types = mm.getObservationTypes();","handlingStrategy":"try-catch","validationCode":"let managerReady = false;\nasync function initManager(m, modeId) { await m.loadMode(modeId); managerReady = true; }\nif (!managerReady) throw new Error('ModeManager not initialized');","typeGuard":"const isReady = (m: ModeManager & { activeMode?: unknown }): boolean => (m as any).activeMode != null;","tryCatchPattern":"try { const types = manager.getObservationTypes(); } catch (e) { if (e.message.includes('No mode loaded')) { await manager.loadMode('code'); return manager.getObservationTypes(); } throw e; }","preventionTips":["Make loadMode part of an explicit init() and gate all accessors on it.","Await manager initialization before reading observation types.","Do not swallow loadMode rejections — a swallowed failure leads to this error later.","In tests, always load a mode in beforeEach before touching accessors."],"tags":["mode-manager","initialization-order","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}