cube-js/cube · error · UserError

Invalid interval: ${interval}

Error message

Invalid interval: ${interval}

What it means

parseInterval expects a string of the form '<number> <unit>' where unit is one of second(s), minute(s), hour(s), day(s), week(s), month(s), quarter(s), year(s) — e.g. '1 hour'. Any string not matching the regex throws this UserError.

Source

Thrown at packages/cubejs-schema-compiler/src/adapter/BaseQuery.js:5021

    ) {
      return 'minute';
    } else if (
      obj.milliseconds === 0
    ) {
      return 'second';
    }
    return 'second'; // TODO return 'millisecond';
  }

  /**
   * @protected
   * @param {string} interval
   * @return {[number, string]}
   */
  parseInterval(interval) {
    const intervalMatch = interval.match(/^(-?\d+) (second|minute|hour|day|week|month|quarter|year)s?$/);
    if (!intervalMatch) {
      throw new UserError(`Invalid interval: ${interval}`);
    }

    const duration = parseInt(intervalMatch[1], 10);

    return [duration, intervalMatch[2]];
  }

  negateInterval(interval) {
    const [duration, grunularity] = this.parseInterval(interval);

    return `${duration * -1} ${grunularity}`;
  }

  parseSecondDuration(interval) {
    const [duration, type] = this.parseInterval(interval);

    const secondsInInterval = SecondsDurations[type];
    return secondsInInterval * duration;

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Rewrite the interval as '<integer> <unit>' with unit in second/minute/hour/day/week/month/quarter/year, e.g. '10 minutes'
  2. Convert ISO-8601 durations to the Cube form ('PT1H' -> '1 hour')
  3. Ensure the value is a string, not a number or object

Example fix

// before
refreshKey: { every: 'PT1H' }
// after
refreshKey: { every: '1 hour' }
Defensive patterns

Strategy: validation

Validate before calling

const RE = /^(-?\d+) (second|minute|hour|day|week|month|quarter|year)s?$/;
function validateInterval(interval) { if (!RE.test(String(interval))) throw new Error(`Invalid interval: ${interval}`); }

Type guard

const isValidInterval = (v) => typeof v === 'string' && /^(-?\d+) (second|minute|hour|day|week|month|quarter|year)s?$/.test(v);

Try / catch

try { await cubeApi.query(q); } catch (e) { if (/Invalid interval:/.test(e.message)) console.error('Use "<n> <unit>" form, e.g. "1 hour"'); throw e; }

Prevention

When it happens

Trigger: Passing 'hour', '1h', '60 minutes and 30 seconds', '1 Hour' with odd casing is fine? — actually casing is fixed: e.g. every: '2 days ' with trailing content, or refreshKeyRenewalThreshold receiving 'PT1H' ISO-8601 durations.

Common situations: Using ISO-8601 duration strings ('PT10M') instead of '<n> <unit>'; missing the number ('hour'); pluralization/unit typos ('fortnight', 'hr'); passing a number instead of string in JS configs.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/be3fd4aa50d34923. Report an issue: GitHub.