{"record":{"id":"0be8de79d2454ecd","repo":"octobercms/october","slug":"cms-lang-cms-object-file-name-required","errorCode":null,"errorMessage":"cms::lang.cms_object.file_name_required","messagePattern":"cms::lang\\.cms_object\\.file_name_required","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"warning","filePath":"modules/cms/classes/Lang.php","lineNumber":335,"sourceCode":"                    ['name' => $this->fileName]\n                ));\n            }\n        }\n    }\n\n    /**\n     * validateFileName supplied with extension and path.\n     */\n    protected function validateFileName($fileName = null)\n    {\n        if ($fileName === null) {\n            $fileName = $this->fileName;\n        }\n\n        $fileName = trim($fileName);\n\n        if (!strlen($fileName)) {\n            throw new ValidationException(['fileName' =>\n                LangHelper::get('cms::lang.cms_object.file_name_required', [\n                    'allowed' => implode(', ', $this->allowedExtensions),\n                    'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)\n                ])\n            ]);\n        }\n\n        if (!FileHelper::validateExtension($fileName, $this->allowedExtensions, false)) {\n            throw new ValidationException(['fileName' =>\n                LangHelper::get('cms::lang.cms_object.invalid_file_extension', [\n                    'allowed' => implode(', ', $this->allowedExtensions),\n                    'invalid' => pathinfo($fileName, PATHINFO_EXTENSION)\n                ])\n            ]);\n        }\n\n        if (!FileHelper::validatePath($fileName, null)) {\n            throw new ValidationException(['fileName' =>","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/Lang.php#L317-L353","documentation":"ValidationException thrown by `Lang::validateFileName()` (called from save() and delete()) when the trimmed file name is an empty string. The message also lists the allowed extensions (json) so the user knows the expected format. This fires before any disk operation, so nothing is written or removed.","triggerScenarios":"Saving a Lang object that was never given a fileName (e.g. `new Lang` + fill(['content' => ...]) then save()); a form/AJAX request submitting a blank file name field; whitespace-only file name from an import.","commonSituations":"Front-end forms missing a required-field check before posting to the CMS API; import scripts with empty rows; programmatic creation that assumes a default name exists.","solutions":["Always set a non-empty file name before save (e.g. 'en.json').","Add required validation on the client/form side so blank names never reach the API.","Default the name programmatically when creating: `$lang->fileName = $lang->fileName ?: 'en.json';`."],"exampleFix":"// before\n$lang->fill(['fileName' => '   ', 'content' => '{}']);\n$lang->save(); // throws file_name_required\n\n// after\n$lang->fill(['fileName' => 'en.json', 'content' => '{}']);\n$lang->save();","handlingStrategy":"validation","validationCode":"$name = trim((string) $request->input('fileName', ''));\nif ($name === '') {\n    throw new ValidationException(['fileName' => 'File name is required.']);\n}\n$lang->fileName = $name;\n$lang->save();","typeGuard":null,"tryCatchPattern":"try {\n    $lang->save();\n} catch (Winter\\Storm\\Exception\\ValidationException $e) {\n    return back()->withErrors($e->getErrors())->withInput();\n}","preventionTips":["Make the file-name field required in your form validation rules before submission.","Default new lang objects to a sensible name ('en.json') when creating them programmatically.","Trim and reject whitespace-only input at the boundary."],"tags":["validation","filename","required-field","lang"],"backgroundTag":"required-field-missing","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}