diff --git a/covalent/_serialize/common.py b/covalent/_serialize/common.py index 341e112f0..8a633c898 100644 --- a/covalent/_serialize/common.py +++ b/covalent/_serialize/common.py @@ -97,7 +97,10 @@ def deserialize_asset(data: bytes, data_type: AssetType) -> Any: elif data_type == AssetType.JSONABLE: return json.loads(data.decode("utf-8")) elif data_type == AssetType.TEXT: - return data.decode("utf-8") + try: + return data.decode("utf-8") + except UnicodeDecodeError: + return cloudpickle.loads(data) elif data_type == AssetType.BYTES: return data else: @@ -170,6 +173,9 @@ def load_asset(asset_meta: AssetSchema, data_type: AssetType) -> Any: path = uri[len(scheme_prefix) :] if uri.startswith(scheme_prefix) else uri - with open(path, "rb") as f: - data = f.read() + try: + with open(path, "rb") as f: + data = f.read() + except FileNotFoundError: + data = "".encode("utf-8") return deserialize_asset(data, data_type)