AlistGo/alist · error

invalid line: %s, because file size must be an integer

Error message

invalid line: %s, because file size must be an integer

What it means

In a url_tree line 'Name:Size:...', the second colon-separated field must parse as a base-10 64-bit integer via strconv.ParseInt. Any non-numeric size (or overflow) fails and aborts tree parsing with the offending line included.

Source

Thrown at drivers/url_tree/util.go:126

	info := line[:index]
	node := &Node{
		Url: url,
	}
	haveSize := false
	if index > 0 {
		if !strings.HasSuffix(info, ":") {
			return nil, fmt.Errorf("invalid line: %s, because file info must end with ':'", line)
		}
		info = info[:len(info)-1]
		if info == "" {
			return nil, fmt.Errorf("invalid line: %s, because file name can't be empty", line)
		}
		infoParts := strings.Split(info, ":")
		node.Name = infoParts[0]
		if len(infoParts) > 1 {
			size, err := strconv.ParseInt(infoParts[1], 10, 64)
			if err != nil {
				return nil, fmt.Errorf("invalid line: %s, because file size must be an integer", line)
			}
			node.Size = size
			haveSize = true
			if len(infoParts) > 2 {
				modified, err := strconv.ParseInt(infoParts[2], 10, 64)
				if err != nil {
					return nil, fmt.Errorf("invalid line: %s, because file modified must be an unix timestamp", line)
				}
				node.Modified = modified
			}
		}
	} else {
		node.Name = stdpath.Base(url)
	}
	if !haveSize && headSize {
		size, err := getSizeFromUrl(url)
		if err != nil {
			log.Errorf("get size from url error: %s", err)

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Write sizes as plain byte counts, e.g. movie.mp4:1073741824: https://x/m.mp4.
  2. Omit size entirely (name:URL) if unknown — with head_size enabled the driver can HEAD the URL to fill it in.
  3. Remove thousands separators and units from size fields.

Example fix

// before
movie.mp4:1.5GB: https://x/m.mp4

// after
movie.mp4:1610612736: https://x/m.mp4
Defensive patterns

Strategy: validation

Validate before calling

func validateSizeField(line string) error {
    idx := strings.Index(line, "http")
    if idx <= 0 { return nil }
    info := strings.TrimSuffix(line[:idx], ":")
    parts := strings.Split(info, ":")
    if len(parts) > 1 && parts[1] != "" {
        if _, err := strconv.ParseInt(parts[1], 10, 64); err != nil {
            return fmt.Errorf("size %q must be integer bytes", parts[1])
        }
    }
    return nil
}

Try / catch

if err != nil && strings.Contains(err.Error(), "file size must be an integer") { /* convert human sizes to bytes or omit the field */ }

Prevention

When it happens

Trigger: Sizes like '1.5GB', '10K', negative values encoded oddly, empty size field ('name::https://...' yields '' -> ParseInt error), or numbers exceeding int64.

Common situations: Human-readable sizes pasted from a file listing, localized number formats (commas), or forgetting the size must be in bytes. Error surfaces at Init.

Related errors


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