{"record":{"id":"5310a8dadf58b10a","repo":"thedotmack/claude-mem","slug":"fileedithandler-requires-filepath","errorCode":null,"errorMessage":"fileEditHandler requires filePath","messagePattern":"fileEditHandler requires filePath","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/handlers/file-edit.ts","lineNumber":15,"sourceCode":"\nimport type { EventHandler, NormalizedHookInput, HookResult } from '../types.js';\nimport { executeWithWorkerFallback, isWorkerFallback } from '../../shared/worker-utils.js';\nimport { logger } from '../../utils/logger.js';\nimport { HOOK_EXIT_CODES } from '../../shared/hook-constants.js';\nimport { normalizePlatformSource } from '../../shared/platform-source.js';\nimport { shouldTrackProject } from '../../shared/should-track-project.js';\n\nexport const fileEditHandler: EventHandler = {\n  async execute(input: NormalizedHookInput): Promise<HookResult> {\n    const { sessionId, cwd, filePath, edits } = input;\n    const platformSource = normalizePlatformSource(input.platform);\n\n    if (!filePath) {\n      throw new Error('fileEditHandler requires filePath');\n    }\n\n    logger.dataIn('HOOK', `FileEdit: ${filePath}`, {\n      editCount: edits?.length ?? 0\n    });\n\n    if (!cwd) {\n      throw new Error(`Missing cwd in FileEdit hook input for session ${sessionId}, file ${filePath}`);\n    }\n\n    if (!shouldTrackProject(cwd)) {\n      logger.debug('HOOK', 'Project excluded from tracking, skipping file edit observation', { cwd, filePath });\n      return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS };\n    }\n\n    const result = await executeWithWorkerFallback<{ status?: string }>(\n      '/api/sessions/observations',\n      'POST',","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/cli/handlers/file-edit.ts#L1-L33","documentation":"fileEditHandler.execute throws Error('fileEditHandler requires filePath') when the normalized hook input has no filePath. The handler's whole purpose is applying edits to a specific file, so a missing path is an invariant violation of the input contract.","triggerScenarios":"Invoking fileEditHandler with a NormalizedHookInput built from a payload lacking file_path (Claude Code hook schema uses tool_input.file_path; adapters map it to input.filePath) — e.g. non-edit events (session start, prompts) routed to this handler, or adapter normalization dropping the field because the key name didn't match.","commonSituations":"Hook configuration routing every event to the file-edit handler instead of only PostToolUse edits; upstream tool schema change renaming file_path to path or absolute_path; constructing NormalizedHookInput manually and forgetting filePath.","solutions":["Only route PostToolUse/Edit-type events to fileEditHandler; filter by hook_event_name/tool_name before dispatch","Ensure the payload includes file_path and the adapter maps it to input.filePath","When constructing NormalizedHookInput manually, set filePath to an absolute path","Catch the error and return early/skip for events without a file"],"exampleFix":"// before\nawait fileEditHandler.execute({ sessionId, cwd }); // throws\n// after\nawait fileEditHandler.execute({ sessionId, cwd, filePath: '/abs/path/file.ts', edits });","handlingStrategy":"validation","validationCode":"if (!input.filePath) return { success: false, error: 'no filePath; not an edit event' };\nawait fileEditHandler.execute(input);","typeGuard":"function isFileEditInput(i: NormalizedHookInput): i is NormalizedHookInput & { filePath: string } { return typeof i.filePath === 'string' && i.filePath.length > 0; }","tryCatchPattern":"try { await fileEditHandler.execute(input); } catch (e) { if (e.message === 'fileEditHandler requires filePath') { /* skip or route to generic handler */ } else throw e; }","preventionTips":["Route only PostToolUse/Edit events to fileEditHandler","Verify the adapter maps file_path from the payload to input.filePath","When building inputs manually, always set filePath (absolute path)","Check upstream tool schema for renamed fields (file_path vs path)"],"tags":["input-validation","handler","file-edit"],"backgroundTag":"missing-required-argument","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"}