{"record":{"id":"ee9c26bf1bee0a5e","repo":"microsoft/typescript-go","slug":"w-watched-directory-removed-ee9c26","errorCode":null,"errorMessage":"%w: watched directory removed","messagePattern":"%w: watched directory removed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fswatch/inotify_linux.go","lineNumber":388,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tkept = append(kept, s)\n\t\t\t\t}\n\t\t\t\tif len(kept) == 0 {\n\t\t\t\t\t_, _ = unix.InotifyRmWatch(b.inotify, uint32(wd))\n\t\t\t\t\tdelete(b.subscriptions, wd)\n\t\t\t\t} else {\n\t\t\t\t\tb.subscriptions[wd] = kept\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tw.events.remove(path)\n\t\t// If the watched root itself is gone the kernel has already\n\t\t// auto-removed every wd associated with this dirWatch and no\n\t\t// further events will fire. Surface ErrWatchTerminated so the\n\t\t// caller knows to clean up; the delete event above still\n\t\t// flows through the same callback.\n\t\tif isSelfEvent && path == w.dir {\n\t\t\tw.events.setError(fmt.Errorf(\"%w: watched directory removed\", ErrWatchTerminated))\n\t\t}\n\t}\n\treturn true\n}\n\n// closeWatch mirrors `inotifyBackend::closeWatch`. Iterates every wd that\n// referenced w and removes the matching subscriptions. If a kernel\n// InotifyRmWatch fails we keep processing remaining wds and return the\n// first error encountered; bailing early would leave the internal state\n// half-cleaned and the caller's dirWatch hanging off other wds.\nfunc (b *inotifyBackend) closeWatch(w *dirWatch) error {\n\tvar firstErr error\n\tfor wd, list := range b.subscriptions {\n\t\tkept := list[:0]\n\t\tremovedAny := false\n\t\tfor _, s := range list {\n\t\t\tif s.dirWatch == w {\n\t\t\t\tremovedAny = true","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/fswatch/inotify_linux.go#L370-L406","documentation":"Error \"%w: watched directory removed\" thrown in microsoft/typescript-go.","triggerScenarios":"Thrown at internal/fswatch/inotify_linux.go:388 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}