AlistGo/alist · error

wukong rename failed: code=%d message=%s

Error message

wukong rename failed: code=%d message=%s

What it means

Thrown by the Wukong driver's Rename after POSTing file_id and new_name to /netdisk/user_file/rename_file. The API responded HTTP-level OK but with a non-zero business code, rejecting the rename. Common upstream reasons: the new name is invalid (illegal characters, too long, empty), a same-named entry exists in the folder, or the file_id is unknown.

Source

Thrown at drivers/wukong/driver.go:271

	var resp rawResp
	_, err := d.client.R().
		SetContext(ctx).
		SetQueryParams(map[string]string{
			"aid":             d.Aid,
			"device_platform": "web",
			"language":        d.Language,
		}).
		SetBody(map[string]any{
			"file_id":  asIDValue(srcID),
			"new_name": newName,
		}).
		SetResult(&resp).
		Post("/netdisk/user_file/rename_file")
	if err != nil {
		return err
	}
	if resp.Code != 0 {
		return fmt.Errorf("wukong rename failed: code=%d message=%s", resp.Code, resp.Message)
	}
	return nil
}

func (d *Wukong) Remove(ctx context.Context, obj model.Obj) error {
	fileID := obj.GetID()
	if fileID == "" {
		return errors.New("missing file id")
	}

	var resp rawResp
	_, err := d.client.R().
		SetContext(ctx).
		SetQueryParams(map[string]string{
			"aid":             d.Aid,
			"device_platform": "web",
			"language":        d.Language,
		}).

View on GitHub (pinned to 843d9dc814)

Solutions

  1. List the parent folder and confirm no sibling already uses newName; if it does, ask the user or auto-suffix
  2. Validate newName against forbidden characters, control chars, empty string, and length limits before the call
  3. Refresh the object listing so srcObj.GetID() is current, then retry
  4. Re-login if resp.Message indicates an authorization code

Example fix

// before
if err := d.Rename(ctx, srcObj, newName); err != nil { return err }

// after
if strings.ContainsAny(newName, "\/:*?\"<>|") || strings.TrimSpace(newName) == "" {
    return fmt.Errorf("invalid file name: %q", newName)
}
if err := d.Rename(ctx, srcObj, newName); err != nil { return err }
Defensive patterns

Strategy: validation

Validate before calling

func validWukongName(name string) bool {
    return name != "" && !strings.ContainsAny(name, "\/:*?\"<>|") && len(name) <= 255
}
if !validWukongName(newName) {
    return fmt.Errorf("invalid new name: %q", newName)
}

Try / catch

if err := d.Rename(ctx, srcObj, newName); err != nil {
    if strings.Contains(err.Error(), "exist") {
        return fmt.Errorf("name %q already taken in target folder", newName)
    }
    return err
}

Prevention

When it happens

Trigger: Renaming to a name that already exists among siblings; newName containing / : * ? \" < > or other forbidden characters; renaming a remotely-deleted file whose ID is stale; expired session.

Common situations: Frontend rename dialog passing an unsanitized name; concurrent renames creating name collisions; listings cached across a remote deletion; quota/permission limits on shared folders.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/56f476168096f61c. Report an issue: GitHub.