cube-js/cube · error · UserError

Can't parse date: '${from}'

Error message

Can't parse date: '${from}'

What it means

dateParser handles a 'from X to Y' date-range string from a query's dateRange parameter. The 'from' half is parsed with chrono-node; when chrono returns no results the library throws this UserError because the string is not a recognized natural-language or fixed date expression. Cube throws it instead of silently producing a broken time range for the query.

Source

Thrown at packages/cubejs-api-gateway/src/date-parser.js:77

      moment.tz(timezone).startOf('day').add(-1, 'day'),
      moment.tz(timezone).endOf('day').add(-1, 'day')
    ];
  } else if (dateString.match(/tomorrow/)) {
    momentRange = [
      moment.tz(timezone).startOf('day').add(1, 'day'),
      moment.tz(timezone).endOf('day').add(1, 'day')
    ];
  } else if (dateString.match(/^from (.*) to (.*)$/)) {
    let [, from, to] = dateString.match(/^from(.{0,50})to(.{0,50})$/);
    from = from.trim();
    to = to.trim();

    const current = moment(now).tz(timezone);
    const fromResults = parse(from.trim(), new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));
    const toResults = parse(to.trim(), new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));

    if (!Array.isArray(fromResults) || !fromResults.length) {
      throw new UserError(`Can't parse date: '${from}'`);
    }

    if (!Array.isArray(toResults) || !toResults.length) {
      throw new UserError(`Can't parse date: '${to}'`);
    }

    const exactGranularity = ['second', 'minute', 'hour'].find(g => dateString.indexOf(g) !== -1) || 'day';
    momentRange = [
      momentFromResult(fromResults[0].start, timezone),
      momentFromResult(toResults[0].start, timezone)
    ];

    momentRange = [momentRange[0].startOf(exactGranularity), momentRange[1].endOf(exactGranularity)];
  } else {
    const current = moment(now).tz(timezone);
    const results = parse(dateString, new Date(current.format(moment.HTML5_FMT.DATETIME_LOCAL_MS)));

    if (!results?.length) {

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Check the exact string between 'from' and 'to' in the error message and fix it to a chrono-node parseable expression, e.g. 'from yesterday to today' or 'from 2024-01-01 to 2024-01-31'
  2. Use one of the built-in relative expressions instead: 'last week', 'last 7 days', 'today', 'yesterday', 'tomorrow'
  3. Pass an explicit dateRange array of ISO strings like ['2024-01-01','2024-01-31'] rather than a 'from ... to ...' sentence
  4. Pre-parse the range in client code with chrono-node to confirm it resolves before sending the query

Example fix

// before
{ dateRange: ['from 01-31-2024 to 02-31-2024'] }
// after
{ dateRange: ['from 2024-01-31 to 2024-02-28'] }
Defensive patterns

Strategy: fallback

Validate before calling

// Scan SQL for unsupported functions before sending to Cube SQL API
function usesUnsupportedFn(sql) {
  return /\bDAYOFWEEK\s*\(/i.test(sql);
}
if (usesUnsupportedFn(sql)) throw new Error('DAYOFWEEK is not implemented in CubeSQL; rewrite the query');

Type guard

function isSupportedDateFn(fnName, supported = ['year','quarter','month','week','day','date_trunc']) {
  return supported.includes(fnName.toLowerCase());
}

Try / catch

try {
  return await connection.query(sql);
} catch (e) {
  if (/Not implemented/.test(String(e.message))) {
    return await connection.query(rewriteDayOfWeek(sql));
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the /cubejs-system/v1 or /load REST API with a dateRange entry matching /^from (.*) to (.*)$/ where the text after 'from' cannot be parsed by chrono-node, e.g. dateRange: ['from 32/45/2024 to next week'], ['from someday to today'], or a locale-specific format like 'from 01.02.2024 to 05.02.2024' that chrono misreads.

Common situations: Passing non-English date strings; passing strict formats like ISO 'YYYY-MM-DD' inside a 'from ... to ...' wrapper that chrono fails on (note plain ISO strings work in the else-branch); typos or placeholder values left in dashboard filter code; upgrading environments where chrono parsing behavior changed.

Related errors


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