{"record":{"id":"7f1e92c97e807702","repo":"deepfakes/faceswap","slug":"error-writing-to-filename-err-strerror","errorCode":null,"errorMessage":"Error writing to '{filename}': {err.strerror}","messagePattern":"Error writing to '(.+?)': (.+?)","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/serializer.py","lineNumber":77,"sourceCode":"            The path to where the serialized file should be saved\n        data: varies\n            The data that is to be serialized to file\n\n        Example\n        ------\n        >>> serializer = get_serializer('json')\n        >>> data ['foo', 'bar']\n        >>> json_file = '/path/to/json/file.json'\n        >>> serializer.save(json_file, data)\n        \"\"\"\n        logger.debug(\"filename: %s, data type: %s\", filename, type(data))\n        filename = self._check_extension(filename)\n        try:\n            with open(filename, self._write_option) as s_file:\n                s_file.write(self.marshal(data))\n        except IOError as err:\n            msg = f\"Error writing to '{filename}': {err.strerror}\"\n            raise FaceswapError(msg) from err\n\n    def _check_extension(self, filename):\n        \"\"\" Check the filename has an extension. If not add the correct one for the serializer \"\"\"\n        extension = os.path.splitext(filename)[1]\n        retval = filename if extension else f\"{filename}.{self.file_extension}\"\n        logger.debug(\"Original filename: '%s', final filename: '%s'\", filename, retval)\n        return retval\n\n    def load(self, filename):\n        \"\"\" Load data from an existing serialized file\n\n        Parameters\n        ----------\n        filename: str\n            The path to the serialized file\n\n        Returns\n        ----------","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/serializer.py#L59-L95","documentation":"Serializer.save wraps file-write IOErrors: opening or writing the serialized file failed (permission denied, disk full, directory missing, path is a directory) and faceswap re-raises as FaceswapError including the OS strerror. The filename may have had the serializer's default extension appended by _check_extension.","triggerScenarios":"Saving a state/alignments file to a non-existent directory, read-only location, full disk, or path where a directory of the same name exists.","commonSituations":"Output dir never created (faceswap usually mkdirs, custom callers may not); disk quota exhausted on long training runs writing state files; permissions on config dirs.","solutions":["Create the parent directory before saving: os.makedirs(os.path.dirname(filename), exist_ok=True).","Free disk space / raise quota if strerror mentions space.","Fix permissions on the target directory or choose a writable location."],"exampleFix":"import os\nfrom lib.serializer import get_serializer\n\n# before\nget_serializer('json').save('/out/missing/state.json', data)  # IOError -> FaceswapError\n\n# after\nos.makedirs('/out/missing', exist_ok=True)\nget_serializer('json').save('/out/missing/state.json', data)","handlingStrategy":"validation","validationCode":"import os\n\nos.makedirs(os.path.dirname(filename) or '.', exist_ok=True)\nassert os.access(os.path.dirname(filename) or '.', os.W_OK), 'no write permission'","typeGuard":null,"tryCatchPattern":"try:\n    serializer.save(filename, data)\nexcept FaceswapError as err:\n    if 'Error writing' in str(err):\n        serializer.save(fallback_filename, data)  # e.g. /tmp fallback\n    else:\n        raise","preventionTips":["mkdir parent directories before every save.","Monitor disk space on long-running jobs that write state files.","Prefer writable scratch dirs over system paths."],"tags":["io","filesystem","serialization","permissions"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}