{"record":{"id":"fe343ada72379d1f","repo":"octobercms/october","slug":"metric-not-found-metriccode","errorCode":null,"errorMessage":"Metric not found: $metricCode","messagePattern":"Metric not found: \\$metricCode","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/dashboard/classes/ReportDataQueryBuilder.php","lineNumber":326,"sourceCode":"\n        return $wrappedQuery->count();\n    }\n\n    /**\n     * getMetricTotals returns totals for metric with the metric totals or the relative bar enabled.\n     * @param ReportMetricConfiguration[] $metricsConfiguration\n     * @return array Returns an array of metric total values\n     */\n    public function getMetricTotals(array $metricsConfiguration): array\n    {\n        // Totals use the same query as for dimensions but without grouping or pagination.\n\n        $metrics = [];\n        foreach ($metricsConfiguration as $metricCode => $configuration) {\n            if ($configuration->getDisplayTotals() || $configuration->getDisplayRelativeBar()) {\n                $metric = ReportMetric::findMetricByCode($this->metrics, $metricCode);\n                if (!$metric) {\n                    throw new ApplicationException(\"Metric not found: $metricCode\");\n                }\n\n                $metrics[] = $metric;\n            }\n        }\n\n        if (!count($metrics)) {\n            return [];\n        }\n\n        $query = $this->createQueryBuilder(true, $metrics);\n        $rows = $query->get()->toArray();\n        if (!count($rows)) {\n            return [];\n        }\n\n        $row = $rows[0];\n        $result = [];","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/dashboard/classes/ReportDataQueryBuilder.php#L308-L344","documentation":"ApplicationException thrown while ReportDataQueryBuilder::getMetricTotals is assembling totals: it looks up each metric configuration by code in the query builder's internal metric set and the given $metricCode has no matching registered metric. It fires when the report's metric configuration references a metric code that the data source / builder does not define (or it was renamed/removed).","triggerScenarios":"Thrown at modules/dashboard/classes/ReportDataQueryBuilder.php:326 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Correct the metric code in the report configuration so it matches a metric actually registered by the data source","Register the missing metric code on the data source / query builder side","Clear cached report configurations after renaming a metric code"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","contentChangedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}