toeverything/AFFiNE · error · Error

Invalid delta range or bound size.

Error message

Invalid delta range or bound size.

What it means

inflateBound computes the expanded rectangle from a delta and throws when the result has non-positive width or height, i.e. the caller requested an inflation that would collapse or invert the bound — a pure geometry input validation.

Source

Thrown at blocksuite/framework/global/src/gfx/bound.ts:138

  );
}

export function getBoundFromPoints(points: IVec[]) {
  return Bound.from(getIBoundFromPoints(points));
}

export function inflateBound(bound: IBound, delta: number) {
  const half = delta / 2;

  const newBound = new Bound(
    bound.x - half,
    bound.y - half,
    bound.w + delta,
    bound.h + delta
  );

  if (newBound.w <= 0 || newBound.h <= 0) {
    throw new Error('Invalid delta range or bound size.');
  }

  return newBound;
}

export function transformPointsToNewBound<T extends { x: number; y: number }>(
  points: T[],
  oldBound: IBound,
  oldMargin: number,
  newBound: IBound,
  newMargin: number
) {
  const wholeOldMargin = oldMargin * 2;
  const wholeNewMargin = newMargin * 2;
  const oldW = Math.max(oldBound.w - wholeOldMargin, 1);
  const oldH = Math.max(oldBound.h - wholeOldMargin, 1);
  const newW = Math.max(newBound.w - wholeNewMargin, 1);
  const newH = Math.max(newBound.h - wholeNewMargin, 1);

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Ensure the delta range (start/end or offset/length) lies within the bound's size before applying it.
  2. Clamp the delta range to the bound's dimensions: range.start >= bound.min and range.end <= bound.max.
  3. Verify the bound itself is valid (w >= 0, h >= 0) before computing delta ranges against it.

Example fix

const clamped = {
  start: Math.max(0, Math.min(delta.start, bound.maxX)),
  end: Math.max(0, Math.min(delta.end, bound.maxX)),
};
if (clamped.end < clamped.start) throw new Error('Invalid delta range');
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at blocksuite/framework/global/src/gfx/bound.ts:138 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/d7c667bf25665d3d. Report an issue: GitHub.