AlistGo/alist · error

file id is empty

Error message

file id is empty

What it means

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.

Source

Thrown at drivers/guangyapan/driver.go:273

		"parentId": parentID,
		"dirName":  name,
	}, &out); err != nil {
		return err
	}
	if !strings.EqualFold(strings.TrimSpace(out.Msg), "success") {
		return fmt.Errorf("make dir failed: %s", strings.TrimSpace(out.Msg))
	}
	return nil
}

func (d *GuangYaPan) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
	if err := d.ensureAccessToken(ctx); err != nil {
		return err
	}

	fileID := strings.TrimSpace(srcObj.GetID())
	if fileID == "" {
		return errors.New("file id is empty")
	}
	name := strings.TrimSpace(newName)
	if name == "" {
		return errors.New("new name is empty")
	}

	var out commonResp
	if err := d.postAPI(ctx, "/nd.bizuserres.s/v1/file/rename", map[string]any{
		"fileId":  fileID,
		"newName": name,
	}, &out); err != nil {
		return err
	}
	if !strings.EqualFold(strings.TrimSpace(out.Msg), "success") {
		return fmt.Errorf("rename failed: %s", strings.TrimSpace(out.Msg))
	}
	return nil
}

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Refresh/re-list the parent directory so objects carry current IDs, then rename
  2. Do not rename root or synthetic objects — only real files/folders returned by List
  3. If it persists, reload the storage to rebuild caches
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(srcObj.GetID()) == "" {
	return fmt.Errorf("object %q has no file id; re-list the directory", srcObj.GetPath())
}
return d.Rename(ctx, srcObj, newName)

Type guard

func hasFileID(o model.Obj) bool { return strings.TrimSpace(o.GetID()) != "" }

Try / catch

if err := d.Rename(ctx, obj, newName); err != nil {
	if strings.Contains(err.Error(), "file id is empty") {
		fresh, _ := d.get(ctx, obj.GetPath())
		if fresh != nil { return d.Rename(ctx, fresh, newName) }
	}
	return err
}

Prevention

When it happens

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

Common situations: Attempting to rename the mount root; object cache out of date after re-authentication; entry obtained from search/index rather than directory listing.

Related errors


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