AlistGo/alist · error

wukong create directory failed: code=%d message=%s

Error message

wukong create directory failed: code=%d message=%s

What it means

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).

Source

Thrown at drivers/wukong/driver.go:208

	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{
			"father_id": asIDValue(fatherID),
			"file_name": dirName,
		}).
		SetResult(&resp).
		Post("/netdisk/user_file/create_directory")
	if err != nil {
		return err
	}
	if resp.Code != 0 {
		return fmt.Errorf("wukong create directory failed: code=%d message=%s", resp.Code, resp.Message)
	}
	return nil
}

func (d *Wukong) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
	srcID := srcObj.GetID()
	if srcID == "" {
		return errors.New("missing source file id")
	}

	dstID := dstDir.GetID()
	if dstID == "" {
		dstID = d.RootFolderID
	}

	var resp rawResp
	_, err := d.client.R().
		SetContext(ctx).

View on GitHub (pinned to 843d9dc814)

Solutions

  1. 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
  2. Verify dstDir.GetID() resolves to an existing remote folder (re-List the parent) and refresh the driver's root folder ID
  3. Re-login / refresh the Wukong credential stored in driver storage if the code indicates an auth failure, then retry
  4. Sanitize dirName for forbidden characters and empty string before calling the API
  5. Inspect resp.Message in the returned error to map the exact business code to the upstream Wukong error table

Example fix

// before
if err := d.MakeDir(ctx, dstDir, dirName); err != nil {
    return err
}

// after
if err := d.MakeDir(ctx, dstDir, dirName); err != nil {
    if strings.Contains(err.Error(), "already exist") { // map actual code/message
        return nil // idempotent: folder already there
    }
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling MakeDir
siblings, err := d.List(ctx, model.NewObjByPath(parentPath))
if err == nil {
    for _, o := range siblings {
        if o.GetName() == dirName && o.IsDir() {
            return nil // already exists: skip create
        }
    }
}
if dirName == "" || strings.ContainsAny(dirName, "\/:*?\"<>|") {
    return fmt.Errorf("invalid directory name: %q", dirName)
}

Try / catch

if err := d.MakeDir(ctx, dstDir, dirName); err != nil {
    if isWukongCode(err, codeAlreadyExists) { // inspect "code=%d" in message
        return nil // idempotent success
    }
    if isWukongAuthErr(err) {
        return fmt.Errorf("wukong session expired, re-login required: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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