flipped-aurora/gin-vue-admin · error
文件名不能为空
Error message
文件名不能为空
What it means
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.
Source
Thrown at server/service/system/sys_skills.go:707
}
func isSafeFileName(name string) bool {
if strings.TrimSpace(name) == "" {
return false
}
if strings.Contains(name, "..") {
return false
}
if strings.ContainsAny(name, "/\\") {
return false
}
return name == filepath.Base(name)
}
func buildScriptFileName(fileName, scriptType string) (string, string, error) {
clean := strings.TrimSpace(fileName)
if clean == "" {
return "", "", errors.New("文件名不能为空")
}
if !isSafeFileName(clean) {
return "", "", errors.New("文件名不合法")
}
base := strings.TrimSuffix(clean, filepath.Ext(clean))
if base == "" {
return "", "", errors.New("文件名不合法")
}
switch strings.ToLower(scriptType) {
case "py", "python":
return base + ".py", "python", nil
case "js", "javascript", "script":
return base + ".js", "javascript", nil
case "sh", "shell", "bash":
return base + ".sh", "sh", nil
default:
return "", "", errors.New("脚本类型不支持")View on GitHub (pinned to 3136500ef3)
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'.
Example fix
// before CreateScript(tool, skill, "", "py") // after CreateScript(tool, skill, "main", "py")
Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(fileName) == "" {
return errors.New("fileName is required")
}
err := svc.CreateScript(tool, skill, fileName, scriptType, content) Type guard
func hasFileName(s string) bool { return strings.TrimSpace(s) != "" } Try / catch
if _, _, err := buildScriptFileName(fileName, scriptType); err != nil {
if strings.Contains(err.Error(), "文件名不能为空") {
fileName = defaultScriptName // e.g. "script"
}
return err
} Prevention
- 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.
When it happens
Trigger: CreateScript invoked with fileName="" or fileName=" "; request field omitted in the JSON payload; UI passes an unset variable.
Common situations: Frontend create-script dialog submits before the user types a name; API consumer forgets the fileName key; a form autofill left the field blank.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/d464af2acdf86f4e.
Report an issue: GitHub.