{"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/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/framework/store/src/transformer/assets.ts#L79-L106","documentation":"AssetsManager.writeToBlob(blobId) looks the id up in its in-memory _assetsMap and throws TransformerError if it is absent. The map is populated only by readFromBlob, so every blob must first be loaded from the source blob storage before it can be written to the target. Note that readFromBlob silently skips missing blobs (it console.errors 'Blob ... not found in blob manager' and returns), so a missing source blob turns into this throw later at write time.","triggerScenarios":"Calling assets.writeToBlob(id) before awaiting assets.readFromBlob(id); the snapshot references a blobId that no longer exists in the source blob storage (readFromBlob skipped it); blobs deleted between export and import.","commonSituations":"Importing snapshots whose assets were stripped or never uploaded; cross-workspace import where the source storage lacks the referenced blob ids; blob GC running before the copy completes.","solutions":["Always await assets.readFromBlob(blobId) before assets.writeToBlob(blobId).","Check assets.getAssets().has(blobId) before writing and skip (or report) ids that failed to load.","Ensure the source blob storage actually contains the referenced blobs (upload or copy them first)."],"exampleFix":"// before\nawait assets.writeToBlob(blobId);\n\n// after\nawait assets.readFromBlob(blobId);\nif (assets.getAssets().has(blobId)) {\n  await assets.writeToBlob(blobId);\n} else {\n  console.warn(`skipping missing blob ${blobId}`);\n}","handlingStrategy":"validation","validationCode":"for (const blobId of blobIds) {\n  await assets.readFromBlob(blobId);\n  if (!assets.getAssets().has(blobId)) {\n    console.warn(`blob ${blobId} missing in source storage; skipping`);\n    continue;\n  }\n  await assets.writeToBlob(blobId);\n}","typeGuard":"const isLoadedAsset = (assets: AssetsManager, blobId: string): boolean =>\n  assets.getAssets().has(blobId);","tryCatchPattern":"try {\n  await assets.writeToBlob(blobId);\n} catch (e) {\n  if (e instanceof BlockSuiteError && e.message.includes('not found in assets manager')) {\n    await assets.readFromBlob(blobId); // load, then retry once\n    await assets.writeToBlob(blobId);\n  } else throw e;\n}","preventionTips":["Always pair writeToBlob with a preceding awaited readFromBlob for the same id.","Remember readFromBlob fails silently for missing blobs — check getAssets().has() afterwards.","Verify referenced blob ids exist in the source storage before starting an import."],"tags":["blob","assets","transformer","snapshot","import"],"backgroundTag":"missing-asset","analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}