cube-js/cube · error · UserError

Unsupported dbt metric type

Error message

Unsupported dbt metric type '${dbtMetricType}'

What it means

The dbt-to-Cube schema extension only knows how to translate dbt metrics whose type appears in its dbtToCubeMetricTypeMap (sum, count, count_distinct, avg, min, max, etc.). mapMetricType is called from cubeDef when converting each manifest metric to a Cube measure, and if the type string from the manifest has no mapping, this UserError is thrown.

Solutions

  1. Change the metric type in the dbt project to one supported by Cube (sum, count, count_distinct, average, min, max as mapped by the extension) and re-run 'dbt compile'
  2. Manually define the metric as a measure in the Cube schema instead of importing it from dbt
  3. Upgrade the cubejs-dbt-schema-extension package to a version whose metric type map covers your dbt version's metric types
  4. Patch/extend dbtToCubeMetricTypeMap to include the missing type if self-hosting/forking

Example fix

// dbt metrics.yml before
- name: avg_revenue
  type: average_price  # unsupported
// after
- name: avg_revenue
  type: average
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['sum','count','count_distinct','average','avg','min','max'];
if (!SUPPORTED.includes(metric.type)) {
  throw new Error(`Metric ${metric.name}: dbt type '${metric.type}' not supported by Cube dbt extension`);
}

Type guard

function isSupportedMetricType(t) {
  return typeof t === 'string' && ['sum','count','count_distinct','average','avg','min','max'].includes(t);
}

Try / catch

try {
  await dbt.loadMetricCubesFromDbtProject(path, opts);
} catch (e) {
  if (/Unsupported dbt metric type/.test(e.message)) {
    console.warn('Skipping project: unsupported metric type', e.message);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Running loadMetricCubesFromDbtProject/loadMetricCubesFromDbtCloud where the dbt manifest contains a metric with type 'average' or any type alias/identifier not present in the map (e.g. derived/ratio metrics, expression metrics, or newer dbt metric types like conversion windows).

Common situations: Upgrading dbt produces new metric types unknown to the Cube extension; hand-edited or generated manifest.json uses 'average' instead of 'avg'; using dbt 1.5+ metric spec with types the extension predates; typos in metric type in the dbt project.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at packages/cubejs-dbt-schema-extension/src/Dbt.ts:129

  }
}
`;

// For reference:
// - dbt Metrics types: https://docs.getdbt.com/docs/building-a-dbt-project/metrics, https://github.com/dbt-labs/dbt-core/issues/4071#issue-102758091
// - Cube measure types: https://cube.dev/docs/schema/reference/types-and-formats#measures-types
const dbtToCubeMetricTypeMap: Record<string, string> = {
  count: 'count',
  count_distinct: 'countDistinct',
  sum: 'sum',
  average: 'avg',
  min: 'min',
  max: 'max',
};

function mapMetricType(dbtMetricType: string): string {
  if (!dbtToCubeMetricTypeMap[dbtMetricType]) {
    throw new UserError(`Unsupported dbt metric type '${dbtMetricType}'`);
  }

  return dbtToCubeMetricTypeMap[dbtMetricType];
}

export class Dbt extends AbstractExtension {
  public async loadMetricCubesFromDbtProject(projectPath: string, options: DbtLoadOptions): Promise<{ [cubeName: string]: any }> {
    const dbtProjectPath = path.join(projectPath, 'dbt_project.yml');
    if (!(await fs.pathExists(dbtProjectPath))) {
      throw new UserError(`'${dbtProjectPath}' was not found. Please make sure '${projectPath}' is a path to the dbt project`);
    }
    // TODO read target path from dbt_project.yml
    const manifestPath = path.join(projectPath, 'target', 'manifest.json');
    if (!(await fs.pathExists(manifestPath))) {
      throw new UserError(`'${manifestPath}' was not found. Please run 'dbt compile' in '${projectPath}'`);
    }
    const manifest = <DbtManifest>(await fs.readJSON(manifestPath));
    Object.keys(manifest.metrics).forEach(metric => {

View on GitHub (pinned to 7d981676b3)