{"record":{"id":"ca57564947787545","repo":"toeverything/AFFiNE","slug":"transformererror","errorCode":"TransformerError","errorMessage":"Blob ${blobId} not found in assets manager","messagePattern":"Blob (.+?) not found in assets manager","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/framework/store/src/transformer/assets.ts","lineNumber":97,"sourceCode":"      this._assetsMap.set(blobId, blob);\n      return;\n    }\n    // Guess the file type from the buffer\n    const buffer = await blob.arrayBuffer();\n    const FileType = await import('file-type');\n    const fileType = await FileType.fileTypeFromBuffer(buffer);\n    if (fileType) {\n      const file = new File([blob], '', { type: fileType.mime });\n      this._assetsMap.set(blobId, file);\n      return;\n    }\n    this._assetsMap.set(blobId, blob);\n  }\n\n  async writeToBlob(blobId: string) {\n    const blob = this._assetsMap.get(blobId);\n    if (!blob) {\n      throw new BlockSuiteError(\n        ErrorCode.TransformerError,\n        `Blob ${blobId} not found in assets manager`\n      );\n    }\n\n    await this._blob.set(blobId, blob);\n  }\n}\n","sourceCodeStart":79,"sourceCodeEnd":106,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/framework/store/src/transformer/assets.ts#L79-L106","documentation":"Thrown by AssetsManager.writeToBlob() when the requested blobId is not present in the internal _assetsMap. The assets manager is a staging area for blobs during snapshot import/export — blobs must first be read or added via readFromBlob() before they can be written. This error indicates a write was attempted for an asset that was never loaded into the manager.","triggerScenarios":"Calling assetsManager.writeToBlob(blobId) without first calling readFromBlob(blobId) or otherwise populating _assetsMap with that blobId. Triggered during snapshot-to-doc import when a block references a blob that wasn't fetched from the blob store.","commonSituations":"Importing a snapshot whose blocks reference blob IDs that don't exist in the source workspace's blob storage. Calling writeToBlob before the async readFromBlob has completed. Assets manager cleanup() was called between read and write, clearing the map.","solutions":["Ensure readFromBlob(blobId) is awaited before calling writeToBlob(blobId) for the same ID.","Verify the blobId actually exists in the underlying blob store (BlobCRUD.get) before attempting to read/write.","Avoid calling assetsManager.cleanup() between read and write operations.","Check snapshot data for stale or invalid blob references and handle missing blobs gracefully."],"exampleFix":"// before\nawait assetsManager.writeToBlob(blobId); // never read -> throws\n\n// after\nawait assetsManager.readFromBlob(blobId);\nawait assetsManager.writeToBlob(blobId);","handlingStrategy":"validation","validationCode":"if (!assetsManager.getAssets().has(blobId)) {\n  await assetsManager.readFromBlob(blobId);\n}\nawait assetsManager.writeToBlob(blobId);","typeGuard":"const isAssetLoaded = (assetsManager: AssetsManager, blobId: string): boolean =>\n  assetsManager.getAssets().has(blobId);","tryCatchPattern":"try {\n  await assetsManager.writeToBlob(blobId);\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.code === ErrorCode.TransformerError) {\n    // attempt to read the blob first, then retry\n    await assetsManager.readFromBlob(blobId);\n    await assetsManager.writeToBlob(blobId);\n  } else throw e;\n}","preventionTips":["Always call readFromBlob before writeToBlob for the same blobId.","Don't call cleanup() between read and write operations.","Validate snapshot blob references before import to catch missing assets early."],"tags":["blocksuite","transformer","assets","blob","import-export"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}