{"record":{"id":"d464af2acdf86f4e","repo":"flipped-aurora/gin-vue-admin","slug":"error-d464af","errorCode":null,"errorMessage":"文件名不能为空","messagePattern":"文件名不能为空","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_skills.go","lineNumber":707,"sourceCode":"}\n\nfunc isSafeFileName(name string) bool {\n\tif strings.TrimSpace(name) == \"\" {\n\t\treturn false\n\t}\n\tif strings.Contains(name, \"..\") {\n\t\treturn false\n\t}\n\tif strings.ContainsAny(name, \"/\\\\\") {\n\t\treturn false\n\t}\n\treturn name == filepath.Base(name)\n}\n\nfunc buildScriptFileName(fileName, scriptType string) (string, string, error) {\n\tclean := strings.TrimSpace(fileName)\n\tif clean == \"\" {\n\t\treturn \"\", \"\", errors.New(\"文件名不能为空\")\n\t}\n\tif !isSafeFileName(clean) {\n\t\treturn \"\", \"\", errors.New(\"文件名不合法\")\n\t}\n\tbase := strings.TrimSuffix(clean, filepath.Ext(clean))\n\tif base == \"\" {\n\t\treturn \"\", \"\", errors.New(\"文件名不合法\")\n\t}\n\n\tswitch strings.ToLower(scriptType) {\n\tcase \"py\", \"python\":\n\t\treturn base + \".py\", \"python\", nil\n\tcase \"js\", \"javascript\", \"script\":\n\t\treturn base + \".js\", \"javascript\", nil\n\tcase \"sh\", \"shell\", \"bash\":\n\t\treturn base + \".sh\", \"sh\", nil\n\tdefault:\n\t\treturn \"\", \"\", errors.New(\"脚本类型不支持\")","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_skills.go#L689-L725","documentation":"buildScriptFileName normalizes a user-provided script file name plus script type into a concrete file name. It returns 文件名不能为空 when the trimmed fileName is the empty string, i.e. CreateScript was called without any file name.","triggerScenarios":"CreateScript invoked with fileName=\"\" or fileName=\"   \"; request field omitted in the JSON payload; UI passes an unset variable.","commonSituations":"Frontend create-script dialog submits before the user types a name; API consumer forgets the fileName key; a form autofill left the field blank.","solutions":["Provide a non-empty fileName such as 'main' or 'main.py'.","Require the file-name input in the UI before allowing submit.","If the name should be auto-generated, generate a default (e.g. 'script') before calling CreateScript.","Check request serialization — the JSON key must be 'fileName', not 'name' or 'file'."],"exampleFix":"// before\nCreateScript(tool, skill, \"\", \"py\")\n// after\nCreateScript(tool, skill, \"main\", \"py\")","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(fileName) == \"\" {\n\treturn errors.New(\"fileName is required\")\n}\nerr := svc.CreateScript(tool, skill, fileName, scriptType, content)","typeGuard":"func hasFileName(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":"if _, _, err := buildScriptFileName(fileName, scriptType); err != nil {\n\tif strings.Contains(err.Error(), \"文件名不能为空\") {\n\t\tfileName = defaultScriptName // e.g. \"script\"\n\t}\n\treturn err\n}","preventionTips":["Require the file-name input before submit in the UI.","Provide a sensible default name when creating scripts programmatically.","Verify the JSON payload key is 'fileName'.","Trim user input server-side but also trim client-side to catch whitespace-only names."],"tags":["validation","missing-field","go"],"backgroundTag":"missing-required-field","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}