{"record":{"id":"afad87bfc2f888c9","repo":"eyaltoledano/claude-task-master","slug":"not-found-afad87","errorCode":"NOT_FOUND","errorMessage":"Tasks file not found. Initialize the project first.","messagePattern":"Tasks file not found\\. Initialize the project first\\.","errorType":"exception","errorClass":"TaskMasterError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.ts","lineNumber":937,"sourceCode":"\t\t\treturn 'master';\n\t\t}\n\t}\n\n\t/**\n\t * Watch for changes to tasks file\n\t * Uses fs.watch with debouncing to detect file changes\n\t */\n\tasync watch(\n\t\tcallback: (event: WatchEvent) => void,\n\t\toptions?: WatchOptions\n\t): Promise<WatchSubscription> {\n\t\tconst tasksPath = this.pathResolver.getTasksPath();\n\t\tconst debounceMs = options?.debounceMs ?? 100;\n\n\t\t// Ensure file exists before watching\n\t\tconst fileExists = await this.fileOps.exists(tasksPath);\n\t\tif (!fileExists) {\n\t\t\tthrow new TaskMasterError(\n\t\t\t\t'Tasks file not found. Initialize the project first.',\n\t\t\t\tERROR_CODES.NOT_FOUND,\n\t\t\t\t{ path: tasksPath }\n\t\t\t);\n\t\t}\n\n\t\tlet debounceTimer: NodeJS.Timeout | undefined;\n\t\tlet closed = false;\n\n\t\tconst watcher = fs.watch(tasksPath, (eventType, filename) => {\n\t\t\tif (closed) return;\n\t\t\tif (filename && eventType === 'change') {\n\t\t\t\tif (debounceTimer) {\n\t\t\t\t\tclearTimeout(debounceTimer);\n\t\t\t\t}\n\t\t\t\tdebounceTimer = setTimeout(() => {\n\t\t\t\t\tif (!closed) {\n\t\t\t\t\t\tcallback({","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.ts#L919-L955","documentation":"FileStorage.watchTasksFile throws a TaskMasterError with code NOT_FOUND when the tasks.json file it is asked to watch does not exist on disk. The watcher requires an existing file and will not start until the project is initialized.","triggerScenarios":"Calling watchTasksFile() (with optional options like debounceMs) in a directory where getTasksPath() does not resolve to an existing file — i.e. before `tm init` or after the file was deleted/moved.","commonSituations":"Starting a watcher in a fresh checkout before initialization; wrong working directory so the resolver points elsewhere; tasks file deleted by a git clean or manual cleanup.","solutions":["Run project initialization (tm init) to create the tasks file before watching","Check existsSync(pathResolver.getTasksPath()) before calling watchTasksFile","Verify the process working directory is the project root","Restore the deleted tasks.json (e.g. from git)"],"exampleFix":"// before\nconst watcher = await storage.watchTasksFile();\n// after\nconst tasksPath = storage.pathResolver.getTasksPath();\nif (!await storage.fileOps.exists(tasksPath)) {\n  throw new Error(`Initialize first: missing ${tasksPath}`);\n}\nconst watcher = await storage.watchTasksFile();","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nconst tasksPath = pathResolver.getTasksPath();\nif (!existsSync(tasksPath)) {\n  throw new Error(`Tasks file missing at ${tasksPath}. Run: tm init`);\n}\nconst watcher = await storage.watchTasksFile();","typeGuard":null,"tryCatchPattern":"try {\n  const watcher = await storage.watchTasksFile();\n} catch (e) {\n  if (e instanceof TaskMasterError && e.code === ERROR_CODES.NOT_FOUND) {\n    await initProject();\n    return await storage.watchTasksFile();\n  }\n  throw e;\n}","preventionTips":["Always run initialization before starting file watchers","Verify process cwd is the project root","Guard watcher startup with an existence check on getTasksPath()","Restore tasks.json from version control if build tools delete it"],"tags":["file-system","watcher","not-found","initialization"],"backgroundTag":"file-not-found","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}