actualbudget/actual · error · Error

Invalid maxDistance: must be a finite positive number greate

Error message

Invalid maxDistance: must be a finite positive number greater than 0

What it means

Error thrown by getNearbyPayees when maxDistance is not a finite number greater than 0. The proximity query needs a positive search radius to bound its results.

Source

Thrown at packages/loot-core/src/server/payees/app.ts:245

  latitude: number;
  longitude: number;
  maxDistance?: number;
}): Promise<NearbyPayeeEntity[]> {
  if (
    !Number.isFinite(latitude) ||
    !Number.isFinite(longitude) ||
    latitude < -90 ||
    latitude > 90 ||
    longitude < -180 ||
    longitude > 180
  ) {
    throw new Error(
      'Invalid coordinates: latitude must be between -90 and 90, longitude must be between -180 and 180',
    );
  }

  if (!Number.isFinite(maxDistance) || maxDistance <= 0) {
    throw new Error(
      'Invalid maxDistance: must be a finite positive number greater than 0',
    );
  }

  // Get the closest location for each payee within maxDistance using window functions
  const query = `
    WITH payee_distances AS (
      SELECT
        pl.id as location_id,
        pl.payee_id,
        pl.latitude,
        pl.longitude,
        pl.created_at,
        p.id,
        p.name,
        p.transfer_acct,
        p.favorite,
        p.learn_categories,

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Pass a finite positive maxDistance (e.g. distance in meters/km per the API's unit)
  2. Default the value when undefined: maxDistance ?? 1000
  3. Guard against 0/negative values from UI inputs before calling
  4. Check unit conversion (km to m, miles to m) for sign and scale errors

Example fix

// before
await app.getNearbyPayees(lat, lon, radiusInput); // may be '' or 0
// after
const dist = Number(radiusInput);
if (Number.isFinite(dist) && dist > 0) {
  await app.getNearbyPayees(lat, lon, dist);
}
Defensive patterns

Strategy: validation

Validate before calling

const d = Number(userDistance);
if (Number.isFinite(d) && d > 0) await app.getNearbyPayees(lat, lon, d);

Try / catch

try {
  return await app.getNearbyPayees(lat, lon, dist);
} catch (e) {
  if (String(e.message).includes('maxDistance')) return await app.getNearbyPayees(lat, lon, 1000);
  throw e;
}

Prevention

When it happens

Trigger: Calling getNearbyPayees with maxDistance = 0, negative values, NaN, Infinity, or undefined.

Common situations: UI slider defaulting to 0, distance in wrong units causing negative values after conversion, config value missing so variable is undefined, user clearing an input field.

Related errors


AI-assisted analysis of actualbudget/actual@d4334cb6e6 (2026-08-29). Data as JSON: /api/errors/5c06eba2e476022f. Report an issue: GitHub.