AlistGo/alist · error

pattern must contain exactly one chunk token: {chunk} or {ch

Error message

pattern must contain exactly one chunk token: {chunk} or {chunk:N}

What it means

parseChunkToken reports this when the chunk name format contains two or more {chunk} or {chunk:N} tokens. Exactly one chunk token is allowed because the compiled printf format has a single numeric verb and the reverse regexp must map each chunk file to one number.

Source

Thrown at drivers/chunker/util.go:142

	switch nameMagicCount {
	case 0:
		return 0, 0, errors.New("pattern must contain one name token: {name}")
	case 1:
	default:
		return 0, 0, errors.New("pattern must contain exactly one name token: {name}")
	}
	start = strings.Index(pattern, "{name}")
	return start, start + len("{name}"), nil
}

func parseChunkToken(pattern string) (start, end, width int, err error) {
	chunkMatches := chunkTokenRegexp.FindAllStringSubmatchIndex(pattern, -1)
	switch len(chunkMatches) {
	case 0:
		return 0, 0, 0, errors.New("pattern must contain one chunk token: {chunk} or {chunk:N}")
	case 1:
	default:
		return 0, 0, 0, errors.New("pattern must contain exactly one chunk token: {chunk} or {chunk:N}")
	}
	match := chunkMatches[0]
	start = match[0]
	end = match[1]
	if match[2] >= 0 && match[3] >= 0 {
		width, err = strconv.Atoi(pattern[match[2]:match[3]])
		if err != nil || width <= 0 {
			return 0, 0, 0, errors.New("chunk width in {chunk:N} must be a positive integer")
		}
	}
	return start, end, width, nil
}

func (d *Chunker) makeChunkName(filePath string, chunkNo int, xactID string) string {
	dir, baseName := path.Split(filePath)
	name := fmt.Sprintf(d.dataNameFmt, baseName, chunkNo+d.StartFrom)
	if xactID != "" {
		name += fmt.Sprintf(tempSuffixFormat, xactID)

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Keep a single {chunk} or {chunk:N} token
  2. For chunk-of-total style names, note total is not expressible — use fixed width {chunk:N} only

Example fix

// before
chunk_name_format: {name}_{chunk:02}_of_{chunk:02}
// after
chunk_name_format: {name}_{chunk:02}
Defensive patterns

Strategy: validation

Validate before calling

var chunkToken = regexp.MustCompile(`\{chunk(:[0-9]+)?\}`)
if n := len(chunkToken.FindAllString(f, -1)); n != 1 {
    return fmt.Errorf("expected exactly 1 chunk token, found %d in %q", n, f)
}

Prevention

When it happens

Trigger: Patterns like '{name}_{chunk}_{chunk:03}' or '{name}-{chunk:N}-{chunk}'. Detected via chunkTokenRegexp.FindAllStringSubmatchIndex returning more than one match; fails at init.

Common situations: Attempting to repeat the chunk number for readability; merging two templates; trying to encode chunk/total (e.g. '{chunk:02}-of-{chunk:02}') which the format language does not support.

Related errors


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