toeverything/AFFiNE · error · BlockSuiteError

ErrorCode.TransformerError

ErrorCode.TransformerError

Error message

value is required

What it means

Thrown by `MemoryBlobCRUD.set` in assets.ts when the call resolves `value` to undefined. The method has two overloads: `set(Blob)` and `set(key, Blob)`; when called in the key form (`valueOrKey` is a string), `_value` must be supplied. If it is missing, the resolved `value` is undefined and the error fires. The class is marked `@internal just for test`.

Source

Thrown at blocksuite/framework/store/src/adapter/assets.ts:34

  }

  list() {
    return Array.from(this._map.keys());
  }

  async set(value: Blob): Promise<string>;

  async set(key: string, value: Blob): Promise<string>;

  async set(valueOrKey: string | Blob, _value?: Blob) {
    const key =
      typeof valueOrKey === 'string'
        ? valueOrKey
        : await sha(await valueOrKey.arrayBuffer());
    const value = typeof valueOrKey === 'string' ? _value : valueOrKey;

    if (!value) {
      throw new BlockSuiteError(
        ErrorCode.TransformerError,
        'value is required'
      );
    }

    this._map.set(key, value);
    return key;
  }
}

export const mimeExtMap = new Map([
  ['application/epub+zip', 'epub'],
  ['application/gzip', 'gz'],
  ['application/java-archive', 'jar'],
  ['application/json', 'json'],
  ['application/ld+json', 'jsonld'],
  ['application/msword', 'doc'],
  ['application/octet-stream', 'bin'],

View on GitHub (pinned to 26c515e050)

Solutions

  1. Pass a non-null `Blob` as the second argument when using the `(key, value)` overload.
  2. Narrow with `if (!blob) return;` before calling `set`.
  3. Prefer the single-argument `set(blob)` overload when you have only a Blob (the key is derived from its sha).

Example fix

// before: key overload called without a blob
await memoryBlob.set(blobId); // _value is undefined

// after: pass the blob explicitly
await memoryBlob.set(blobId, blob);

// or use the single-arg overload to derive the key
const key = await memoryBlob.set(blob);
Defensive patterns

Strategy: validation

Validate before calling

// narrow before calling the key overload
function setBlob(crud: MemoryBlobCRUD, keyOrBlob: string | Blob, value?: Blob) {
  if (typeof keyOrBlob === 'string') {
    if (!value) throw new Error('value is required for the (key, value) overload');
    return crud.set(keyOrBlob, value);
  }
  return crud.set(keyOrBlob);
}

Type guard

function isBlob(v: unknown): v is Blob {
  return v instanceof Blob;
}

Try / catch

try {
  await memoryBlob.set(blobId, blob);
} catch (e) {
  if (e instanceof BlockSuiteError && e.code === ErrorCode.TransformerError) {
    console.error('Blob set failed:', e.message);
  }
}

Prevention

When it happens

Trigger: Calling `memoryBlob.set('some-id')` (no blob), or `memoryBlob.set('some-id', undefined)` — typically a bug in a test helper or a caller that destructured a possibly-undefined blob.

Common situations: Test utilities passing an optional `Blob | undefined` without a guard; refactoring the call sites to drop the second argument; misusing the internal test class in place of the real blob storage.

Related errors


AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12). Data as JSON: /api/errors/3451421fd3e3fcdf. Report an issue: GitHub.