{"record":{"id":"6a07595aded5fa3c","repo":"octobercms/october","slug":"the-dimension-field-code-cannot-be-empty","errorCode":null,"errorMessage":"The dimension field code cannot be empty.","messagePattern":"The dimension field code cannot be empty\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/dashboard/classes/ReportDimensionField.php","lineNumber":53,"sourceCode":"    /**\n     * Creates a new dimension field.\n     * @param string $code Specifies the field referral code.\n     * @param string $displayName Specifies the field name to use in reports.\n     * @param ?string $columnName Optional database column name for filtering or sorting.\n     * Provide the column name if the column added to the SELECT statement cannot be\n     * used directly, such as when it involves an aggregation function.\n     * @param bool $sortable Specifies if the field is sortable.\n     * @param bool $filterable Specifies if the field is filterable.\n     */\n    public function __construct(\n        string $code,\n        string $displayName,\n        ?string $columnName = null,\n        bool $sortable = false,\n        bool $filterable = false\n    ) {\n        if (!strlen($code)) {\n            throw new SystemException('The dimension field code cannot be empty.');\n        }\n\n        self::validateCode($code);\n\n        if (!strlen($displayName)) {\n            throw new SystemException('Display name cannot be empty.');\n        }\n\n        $this->displayName = $displayName;\n        $this->sortable = $sortable;\n        $this->filterable = $filterable;\n        $this->code = $code;\n        $this->columnName = $columnName;\n    }\n\n    /**\n     * Returns the dimension field code.\n     * @return string Returns the dimension field code.","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/dashboard/classes/ReportDimensionField.php#L35-L71","documentation":"ReportDimensionField's constructor requires a non-empty field code, because the code is the identifier used in queries, filters, and cache keys. An empty string throws immediately before any other validation runs.","triggerScenarios":"new ReportDimensionField('', 'Status') or new ReportDimensionField($missingVar ?? '', 'Status') — any constructor call where the $code argument has zero length.","commonSituations":"Dynamically building fields from configuration arrays where a 'code' key is absent and null coalesces to ''; whitespace-only codes (note: strlen(' ') is 1, so ' ' passes this check but fails the later regex); copy-paste templates left with a placeholder code.","solutions":["Make sure the code is a non-empty string built from real data (e.g. 'oc_field_' . $key)","Default missing config keys to a generated code instead of ''","Trim and validate config-derived codes before constructing the field"],"exampleFix":"// before\n$field = new ReportDimensionField($config['code'] ?? '', $config['name']);\n\n// after\n$field = new ReportDimensionField(\n    'oc_field_' . ($config['key'] ?? $config['name']),\n    $config['name']\n);","handlingStrategy":"validation","validationCode":"$code = trim((string) ($config['code'] ?? ''));\nif ($code === '') {\n    throw new InvalidArgumentException('Dimension field code missing in config');\n}\n$field = new ReportDimensionField('oc_field_' . $code, $config['name']);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate config-derived codes for emptiness before building objects","Generate codes from stable keys instead of free-form labels","Catch missing keys early at config load time, not at render time"],"tags":["php","dashboard","report","dimension","field","validation"],"backgroundTag":"empty-required-argument","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}