{"record":{"id":"3def8b259d60dd1f","repo":"aosabook/500lines","slug":"inotify-add-watch-error","errorCode":null,"errorMessage":"inotify_add_watch() error: {}","messagePattern":"inotify_add_watch\\(\\) error: (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"contingent/code/contingent/io.py","lineNumber":47,"sourceCode":"    changed_paths = []\n    while not changed_paths:\n        time.sleep(0.5)\n        changed_paths = [path for path in paths\n                         if os.stat(path).st_mtime > start]\n    return changed_paths\n\ndef inotify_wait_on(paths):\n    paths = [path.encode('ascii') for path in paths]\n    fd = _libc.inotify_init()\n    descriptors = {}\n    if fd == -1:\n        raise OSError('inotify_init() error: {}'.format(\n            os.strerror(ctypes.get_errno())))\n    try:\n        for path in paths:\n            rv = _libc.inotify_add_watch(fd, path, 0x2)\n            if rv == -1:\n                raise OSError('inotify_add_watch() error: {}'.format(\n                    os.strerror(ctypes.get_errno())))\n            descriptors[rv] = path\n        buf = os.read(fd, 1024)\n        # TODO: continue with some more reads with 0.1 second timeouts\n        # to empty the list of roughly-simultaneous events before\n        # closing our file descriptor and returning?\n    finally:\n        pass #os.close(fd)\n    time.sleep(0.1)  # until above TODO is done\n    wd, mask, cookie, name_length = struct.unpack('iIII', buf)\n    return [descriptors[wd].decode('ascii')]\n","sourceCodeStart":29,"sourceCodeEnd":59,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/contingent/code/contingent/io.py#L29-L59","documentation":"Error \"inotify_add_watch() error: {}\" thrown in aosabook/500lines.","triggerScenarios":"Thrown at contingent/code/contingent/io.py:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure every path passed to inotify_wait_on exists and is readable before watching it.","Increase fs.inotify.max_user_watches if the error is ENOSPC (watch limit reached).","Verify paths encode to ASCII; non-ASCII paths must be encoded with the filesystem encoding instead of 'ascii'."],"exampleFix":"sysctl fs.inotify.max_user_watches=524288  # and validate each path with os.path.exists(path) before adding the watch","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}