{"record":{"id":"fdb536a86ca2810c","repo":"deepfakes/faceswap","slug":"error-unserializing-data-for-type-type-serialized","errorCode":null,"errorMessage":"Error unserializing data for type {type(serialized_data)}: {str(err)}","messagePattern":"Error unserializing data for type (.+?): (.+?)","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/serializer.py","lineNumber":170,"sourceCode":"            Data in serializer format that is to be unmarshalled to its original object\n\n        Returns\n        -------\n        data: varies\n            The data in a python object format\n\n        Example\n        ------\n        >>> serializer = get_serializer('json')\n        >>> json_data = <json object>\n        >>> data = serializer.unmarshal(json_data)\n        \"\"\"\n        logger.debug(\"data type: %s\", type(serialized_data))\n        try:\n            retval = self._unmarshal(serialized_data)\n        except Exception as err:\n            msg = f\"Error unserializing data for type {type(serialized_data)}: {str(err)}\"\n            raise FaceswapError(msg) from err\n        logger.debug(\"returned data type: %s\", type(retval))\n        return retval\n\n    def _marshal(self, data):\n        \"\"\" Override for serializer specific marshalling \"\"\"\n        raise NotImplementedError()\n\n    def _unmarshal(self, data):\n        \"\"\" Override for serializer specific unmarshalling \"\"\"\n        raise NotImplementedError()\n\n\nclass _YAMLSerializer(Serializer):\n    \"\"\" YAML Serializer \"\"\"\n    def __init__(self):\n        super().__init__()\n        self._file_extension = \"yml\"\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/serializer.py#L152-L188","documentation":"Serializer.unmarshal wraps ANY exception from the format-specific _unmarshal call: the stored bytes could not be decoded back to objects. Typical causes are JSONDecodeError (corrupt/truncated file, NaN handling), pickle UnpicklingError (protocol or class mismatch), or ValueError from newline-json parsing.","triggerScenarios":"Loading a state file truncated by a crash mid-write; JSON containing NaN/Infinity (strict JSON parsers reject them); pickled data referencing classes that moved/renamed between faceswap versions.","commonSituations":"Hard-killed training jobs leaving partial files; hand-edited JSON with invalid syntax; loading old pickle state after refactors.","solutions":["Inspect str(err) in the message — it identifies the parse failure precisely.","Restore the file from a backup or regenerate it (e.g. re-extract alignments) if corrupt.","For JSON with NaN, re-save with a compliant writer (allow_nan=False) or sanitize the file.","Keep pickle data within the same code version that produced it, or migrate schemas."],"exampleFix":"import json\n\n# before\ndata = serializer.load('/state/train_state.json')  # JSONDecodeError -> FaceswapError\n\n# after: guard and surface a clear message\ntry:\n    data = serializer.load('/state/train_state.json')\nexcept FaceswapError:\n    raise SystemExit('state file corrupt; restore backup or re-run extraction')","handlingStrategy":"try-catch","validationCode":"# cheap sanity check for JSON files\nimport os\nsize = os.path.getsize(filename)\nassert size > 2, 'file too small to contain valid data'","typeGuard":null,"tryCatchPattern":"try:\n    data = serializer.load(filename)\nexcept FaceswapError as err:\n    if 'Error unserializing' in str(err):\n        backup = filename + '.corrupt'\n        os.replace(filename, backup)\n        raise SystemExit(f'state corrupt, moved to {backup}; regenerate it')\n    else:\n        raise","preventionTips":["Write atomically (tmp file + rename) so crashes never leave partial state.","Never hand-edit serialized state without validating JSON syntax after.","Pin the faceswap version that produced pickle state files."],"tags":["serialization","json","pickle","corruption"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}