{"record":{"id":"020c9876c1479120","repo":"AlistGo/alist","slug":"file-id-is-empty","errorCode":null,"errorMessage":"file id is empty","messagePattern":"file id is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/guangyapan/driver.go","lineNumber":273,"sourceCode":"\t\t\"parentId\": parentID,\n\t\t\"dirName\":  name,\n\t}, &out); err != nil {\n\t\treturn err\n\t}\n\tif !strings.EqualFold(strings.TrimSpace(out.Msg), \"success\") {\n\t\treturn fmt.Errorf(\"make dir failed: %s\", strings.TrimSpace(out.Msg))\n\t}\n\treturn nil\n}\n\nfunc (d *GuangYaPan) Rename(ctx context.Context, srcObj model.Obj, newName string) error {\n\tif err := d.ensureAccessToken(ctx); err != nil {\n\t\treturn err\n\t}\n\n\tfileID := strings.TrimSpace(srcObj.GetID())\n\tif fileID == \"\" {\n\t\treturn errors.New(\"file id is empty\")\n\t}\n\tname := strings.TrimSpace(newName)\n\tif name == \"\" {\n\t\treturn errors.New(\"new name is empty\")\n\t}\n\n\tvar out commonResp\n\tif err := d.postAPI(ctx, \"/nd.bizuserres.s/v1/file/rename\", map[string]any{\n\t\t\"fileId\":  fileID,\n\t\t\"newName\": name,\n\t}, &out); err != nil {\n\t\treturn err\n\t}\n\tif !strings.EqualFold(strings.TrimSpace(out.Msg), \"success\") {\n\t\treturn fmt.Errorf(\"rename failed: %s\", strings.TrimSpace(out.Msg))\n\t}\n\treturn nil\n}","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/guangyapan/driver.go#L255-L291","documentation":"GuangYaPan Rename trims srcObj.GetID() and refuses to proceed when it is empty. A rename needs the provider's file ID; an object with a blank ID cannot be addressed, which usually means the obj came from a stale or synthetic listing rather than a fresh API List call.","triggerScenarios":"Renaming an object whose model.Obj carries an empty ID — root pseudo-folder objects, cached entries from before a re-login, or manually constructed objects.","commonSituations":"Attempting to rename the mount root; object cache out of date after re-authentication; entry obtained from search/index rather than directory listing.","solutions":["Refresh/re-list the parent directory so objects carry current IDs, then rename","Do not rename root or synthetic objects — only real files/folders returned by List","If it persists, reload the storage to rebuild caches"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if strings.TrimSpace(srcObj.GetID()) == \"\" {\n\treturn fmt.Errorf(\"object %q has no file id; re-list the directory\", srcObj.GetPath())\n}\nreturn d.Rename(ctx, srcObj, newName)","typeGuard":"func hasFileID(o model.Obj) bool { return strings.TrimSpace(o.GetID()) != \"\" }","tryCatchPattern":"if err := d.Rename(ctx, obj, newName); err != nil {\n\tif strings.Contains(err.Error(), \"file id is empty\") {\n\t\tfresh, _ := d.get(ctx, obj.GetPath())\n\t\tif fresh != nil { return d.Rename(ctx, fresh, newName) }\n\t}\n\treturn err\n}","preventionTips":["Always operate on objects returned from a fresh List call","Treat the root object as non-renameable in UI logic","Reload the storage after re-authentication to invalidate stale ID caches"],"tags":["guangyapan","rename","validation","driver"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}