{"record":{"id":"c213eb52c7867bd6","repo":"AlistGo/alist","slug":"wukong-create-directory-failed-code-d-message-s","errorCode":null,"errorMessage":"wukong create directory failed: code=%d message=%s","messagePattern":"wukong create directory failed: code=(.+?) message=(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/wukong/driver.go","lineNumber":208,"sourceCode":"\tvar resp rawResp\n\t_, err := d.client.R().\n\t\tSetContext(ctx).\n\t\tSetQueryParams(map[string]string{\n\t\t\t\"aid\":             d.Aid,\n\t\t\t\"device_platform\": \"web\",\n\t\t\t\"language\":        d.Language,\n\t\t}).\n\t\tSetBody(map[string]any{\n\t\t\t\"father_id\": asIDValue(fatherID),\n\t\t\t\"file_name\": dirName,\n\t\t}).\n\t\tSetResult(&resp).\n\t\tPost(\"/netdisk/user_file/create_directory\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif resp.Code != 0 {\n\t\treturn fmt.Errorf(\"wukong create directory failed: code=%d message=%s\", resp.Code, resp.Message)\n\t}\n\treturn nil\n}\n\nfunc (d *Wukong) Move(ctx context.Context, srcObj, dstDir model.Obj) error {\n\tsrcID := srcObj.GetID()\n\tif srcID == \"\" {\n\t\treturn errors.New(\"missing source file id\")\n\t}\n\n\tdstID := dstDir.GetID()\n\tif dstID == \"\" {\n\t\tdstID = d.RootFolderID\n\t}\n\n\tvar resp rawResp\n\t_, err := d.client.R().\n\t\tSetContext(ctx).","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/wukong/driver.go#L190-L226","documentation":"Thrown by the Wukong driver's MakeDir after POSTing to /netdisk/user_file/create_directory. The HTTP request itself succeeded, but the response envelope carries a non-zero business code in resp.Code, meaning the Wukong netdisk API refused to create the directory. The API's message field usually names the concrete refusal reason (duplicate name, invalid father_id, permission denied, expired session).","triggerScenarios":"Calling driver MakeDir when a directory with the same name already exists under father_id; passing a father_id that is not a valid folder ID; name containing characters the API rejects; session cookie/token expired so the API returns an auth error code instead of a transport error.","commonSituations":"User creates a folder that already exists in the Wukong web pan; the parent object ID got stale after the remote directory was moved or deleted; the Wukong account was logged in elsewhere invalidating the session; renaming/moving the parent concurrently from the web UI while the driver writes.","solutions":["Retry after listing the parent directory to confirm whether the target name already exists; if so, treat it as success or pick a suffixed name","Verify dstDir.GetID() resolves to an existing remote folder (re-List the parent) and refresh the driver's root folder ID","Re-login / refresh the Wukong credential stored in driver storage if the code indicates an auth failure, then retry","Sanitize dirName for forbidden characters and empty string before calling the API","Inspect resp.Message in the returned error to map the exact business code to the upstream Wukong error table"],"exampleFix":"// before\nif err := d.MakeDir(ctx, dstDir, dirName); err != nil {\n    return err\n}\n\n// after\nif err := d.MakeDir(ctx, dstDir, dirName); err != nil {\n    if strings.Contains(err.Error(), \"already exist\") { // map actual code/message\n        return nil // idempotent: folder already there\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// before calling MakeDir\nsiblings, err := d.List(ctx, model.NewObjByPath(parentPath))\nif err == nil {\n    for _, o := range siblings {\n        if o.GetName() == dirName && o.IsDir() {\n            return nil // already exists: skip create\n        }\n    }\n}\nif dirName == \"\" || strings.ContainsAny(dirName, \"\\/:*?\\\"<>|\") {\n    return fmt.Errorf(\"invalid directory name: %q\", dirName)\n}","typeGuard":null,"tryCatchPattern":"if err := d.MakeDir(ctx, dstDir, dirName); err != nil {\n    if isWukongCode(err, codeAlreadyExists) { // inspect \"code=%d\" in message\n        return nil // idempotent success\n    }\n    if isWukongAuthErr(err) {\n        return fmt.Errorf(\"wukong session expired, re-login required: %w\", err)\n    }\n    return err\n}","preventionTips":["Check the parent listing for name collisions before creating directories","Keep listings fresh (re-List before write operations) to avoid stale father_id","Sanitize names for forbidden characters at the UI boundary, not in the driver"],"tags":["wukong","mkdir","api-error","cloud-storage","go"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}