{"record":{"id":"da95ccd25f9e400d","repo":"microsoft/typescript-go","slug":"fswatch-callback-must-not-be-nil","errorCode":null,"errorMessage":"fswatch: callback must not be nil","messagePattern":"fswatch: callback must not be nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fswatch/watcher.go","lineNumber":17,"sourceCode":"package fswatch\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"slices\"\n\t\"strings\"\n\t\"sync\"\n\t\"syscall\"\n\n\t\"github.com/microsoft/typescript-go/internal/nativepath\"\n)\n\nvar errNilCallback = errors.New(\"fswatch: callback must not be nil\")\n\n// errRootPath is returned by WatchFile when the supplied path is a\n// filesystem root with no parent directory to watch.\nvar errRootPath = errors.New(\"fswatch: cannot watch a root path\")\n\n// errNotAbsolute is returned by [Watcher.WatchDirectory] and\n// [Watcher.WatchFile] when the supplied path is not absolute.\nvar errNotAbsolute = errors.New(\"fswatch: path must be absolute\")\n\n// ErrOverflow indicates that the kernel event queue overflowed and\n// some filesystem changes were missed. The watch remains\n// active; further events will continue to be delivered. Callers\n// should treat this as a signal to rescan the watched directory.\nvar ErrOverflow = errors.New(\"fswatch: event overflow; some changes were missed\")\n\n// ErrWatchTerminated indicates that the watch was terminated due to\n// an unrecoverable error (e.g. the watched directory was deleted or\n// the watch descriptor was revoked). No further events will be","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/fswatch/watcher.go#L1-L35","documentation":"Sentinel error returned when a nil WatchCallback is passed. WatchDirectories checks each request's Callback and rolls back every watch prepared so far before returning it; WatchDirectory delegates to the same path, and WatchFile checks it directly. It signals a programming error at the call site, not an environmental condition.","triggerScenarios":"Calling WatchDirectory(dir, nil). Passing a nil func variable. Constructing WatchDirectoryRequest with a zero-value Callback field.","commonSituations":"Optional-callback layers where nil slips through. Struct literals like WatchDirectoryRequest{Dir: d} with the Callback field forgotten. Refactors that rename the callback parameter and leave the argument position empty.","solutions":["Pass a non-nil callback function","Fail fast in your own wrapper: reject nil callbacks before calling fswatch","If you truly need a no-op, pass an empty function literal instead of nil"],"exampleFix":"// before\nwatch, err := w.WatchDirectory(dir, nil)\n\n// after\nnoop := func(events []fswatch.Event, err error) {}\nwatch, err := w.WatchDirectory(dir, noop)","handlingStrategy":"validation","validationCode":"if cb == nil {\n    return errors.New(\"callback must not be nil\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass nil callbacks; use an empty function for a no-op","Fill in every WatchDirectoryRequest.Callback field; lint struct literals","Validate callback arguments in your own wrappers before calling fswatch","Treat this error as a bug to fix at the call site, not a condition to handle"],"tags":["api-misuse","validation","callback"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}