{"record":{"id":"d22b69b2d907dacc","repo":"cube-js/cube","slug":"unsupported-dbt-metric-type-dbtmetrictype","errorCode":null,"errorMessage":"Unsupported dbt metric type '${dbtMetricType}'","messagePattern":"Unsupported dbt metric type '(.+?)'","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-dbt-schema-extension/src/Dbt.ts","lineNumber":129,"sourceCode":"  }\n}\n`;\n\n// For reference:\n// - dbt Metrics types: https://docs.getdbt.com/docs/building-a-dbt-project/metrics, https://github.com/dbt-labs/dbt-core/issues/4071#issue-102758091\n// - Cube measure types: https://cube.dev/docs/schema/reference/types-and-formats#measures-types\nconst dbtToCubeMetricTypeMap: Record<string, string> = {\n  count: 'count',\n  count_distinct: 'countDistinct',\n  sum: 'sum',\n  average: 'avg',\n  min: 'min',\n  max: 'max',\n};\n\nfunction mapMetricType(dbtMetricType: string): string {\n  if (!dbtToCubeMetricTypeMap[dbtMetricType]) {\n    throw new UserError(`Unsupported dbt metric type '${dbtMetricType}'`);\n  }\n\n  return dbtToCubeMetricTypeMap[dbtMetricType];\n}\n\nexport class Dbt extends AbstractExtension {\n  public async loadMetricCubesFromDbtProject(projectPath: string, options: DbtLoadOptions): Promise<{ [cubeName: string]: any }> {\n    const dbtProjectPath = path.join(projectPath, 'dbt_project.yml');\n    if (!(await fs.pathExists(dbtProjectPath))) {\n      throw new UserError(`'${dbtProjectPath}' was not found. Please make sure '${projectPath}' is a path to the dbt project`);\n    }\n    // TODO read target path from dbt_project.yml\n    const manifestPath = path.join(projectPath, 'target', 'manifest.json');\n    if (!(await fs.pathExists(manifestPath))) {\n      throw new UserError(`'${manifestPath}' was not found. Please run 'dbt compile' in '${projectPath}'`);\n    }\n    const manifest = <DbtManifest>(await fs.readJSON(manifestPath));\n    Object.keys(manifest.metrics).forEach(metric => {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-dbt-schema-extension/src/Dbt.ts#L111-L147","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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'","Manually define the metric as a measure in the Cube schema instead of importing it from dbt","Upgrade the cubejs-dbt-schema-extension package to a version whose metric type map covers your dbt version's metric types","Patch/extend dbtToCubeMetricTypeMap to include the missing type if self-hosting/forking"],"exampleFix":"// dbt metrics.yml before\n- name: avg_revenue\n  type: average_price  # unsupported\n// after\n- name: avg_revenue\n  type: average","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['sum','count','count_distinct','average','avg','min','max'];\nif (!SUPPORTED.includes(metric.type)) {\n  throw new Error(`Metric ${metric.name}: dbt type '${metric.type}' not supported by Cube dbt extension`);\n}","typeGuard":"function isSupportedMetricType(t) {\n  return typeof t === 'string' && ['sum','count','count_distinct','average','avg','min','max'].includes(t);\n}","tryCatchPattern":"try {\n  await dbt.loadMetricCubesFromDbtProject(path, opts);\n} catch (e) {\n  if (/Unsupported dbt metric type/.test(e.message)) {\n    console.warn('Skipping project: unsupported metric type', e.message);\n  } else { throw e; }\n}","preventionTips":["Pin dbt versions and check new metric types against Cube's mapping before upgrading","Prefer core aggregate metric types (sum, count, avg, min, max) in dbt models","Define unsupported metrics directly in Cube schemas instead of via dbt","Test dbt->Cube loading in CI with a representative manifest"],"tags":["dbt","schema-compilation","unsupported-value","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}