GopeedLab/gopeed · error

invalid resource file name

Error message

invalid resource file name

What it means

Resource.Validate() rejects a download resource whose Files slice contains an entry with an empty Name. Validation runs both when a task/resource is submitted directly and when an extension's onResolve handler returns a resource (pkg/download/extension.go:264 logs it as 'resource invalid' and skips it). The check exists because every file entry needs a name to build the download path on disk.

Source

Thrown at pkg/base/model.go:105

	Name string `json:"name"`
	Size int64  `json:"size"`
	// is support range download
	Range bool `json:"range"`
	// file list
	Files []*FileInfo `json:"files"`
	Hash  string      `json:"hash"`
}

func (r *Resource) Validate() error {
	if r.Name == "" {
		return fmt.Errorf("invalid resource name")
	}
	if len(r.Files) == 0 {
		return fmt.Errorf("invalid resource files")
	}
	for _, file := range r.Files {
		if file.Name == "" {
			return fmt.Errorf("invalid resource file name")
		}
	}
	return nil
}

func (r *Resource) CalcSize(selectFiles []int) {
	var size int64
	for i, file := range r.Files {
		if len(selectFiles) == 0 || slices.Contains(selectFiles, i) {
			size += file.Size
		}
	}
	r.Size = size
}

type FileInfo struct {
	Name  string     `json:"name"`
	Path  string     `json:"path"`

View on GitHub (pinned to 7b7327ffb3)

Solutions

  1. Set a non-empty Name on every entry of Resource.Files before creating the task
  2. In extension onResolve, copy the real filename into each file object of the returned resource
  3. If the Resource comes from JSON, verify each file entry unmarshals with a non-empty name before submitting

Example fix

// before (extension onResolve)
const res = gopeed.resource({
  name: 'pkg',
  files: [{ url: 'https://host/f.bin' }],
});
// after
const res = gopeed.resource({
  name: 'pkg',
  files: [{ name: 'f.bin', url: 'https://host/f.bin' }],
});
Defensive patterns

Strategy: validation

Validate before calling

// Go: before creating the task
for i, f := range res.Files {
    if strings.TrimSpace(f.Name) == "" {
        return fmt.Errorf("file %d has empty name: fix or default it", i)
    }
}

Prevention

When it happens

Trigger: Calling the resolve/create API with a base.Resource where some Files[i].Name is "" (e.g. a scraper filled only URL and Size), or an extension onResolve returning gopeed.resource({name:'pkg', files:[{url:'https://host/f.bin'}]}) with the per-file name field missing.

Common situations: Hand-built Resource structs in Go clients; extension scripts mapping file lists from a page and dropping the filename key; JSON manifests where a file entry lacks the "name" key; empty filename after a bad string split on '/' of the URL path.

Related errors


AI-assisted analysis of GopeedLab/gopeed@7b7327ffb3 (2026-08-16). Data as JSON: /api/errors/72a3d1b8cb58dbdb. Report an issue: GitHub.