{"record":{"id":"42cb2e822c3b15fa","repo":"AlistGo/alist","slug":"pattern-must-contain-one-name-token-name","errorCode":null,"errorMessage":"pattern must contain one name token: {name}","messagePattern":"pattern must contain one name token: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/chunker/util.go","lineNumber":126,"sourceCode":"\td.nameRegexp = regexp.MustCompile(strRegex)\n\n\tfmtDigits := \"%d\"\n\tif chunkWidth > 0 {\n\t\tfmtDigits = fmt.Sprintf(\"%%0%dd\", chunkWidth)\n\t}\n\td.dataNameFmt = strings.ReplaceAll(beforeName, \"%\", \"%%\") +\n\t\t\"%s\" +\n\t\tstrings.ReplaceAll(between, \"%\", \"%%\") +\n\t\tfmtDigits +\n\t\tstrings.ReplaceAll(afterChunk, \"%\", \"%%\")\n\treturn nil\n}\n\nfunc parseNameToken(pattern string) (start, end int, err error) {\n\tnameMagicCount := strings.Count(pattern, \"{name}\")\n\tswitch nameMagicCount {\n\tcase 0:\n\t\treturn 0, 0, errors.New(\"pattern must contain one name token: {name}\")\n\tcase 1:\n\tdefault:\n\t\treturn 0, 0, errors.New(\"pattern must contain exactly one name token: {name}\")\n\t}\n\tstart = strings.Index(pattern, \"{name}\")\n\treturn start, start + len(\"{name}\"), nil\n}\n\nfunc parseChunkToken(pattern string) (start, end, width int, err error) {\n\tchunkMatches := chunkTokenRegexp.FindAllStringSubmatchIndex(pattern, -1)\n\tswitch len(chunkMatches) {\n\tcase 0:\n\t\treturn 0, 0, 0, errors.New(\"pattern must contain one chunk token: {chunk} or {chunk:N}\")\n\tcase 1:\n\tdefault:\n\t\treturn 0, 0, 0, errors.New(\"pattern must contain exactly one chunk token: {chunk} or {chunk:N}\")\n\t}\n\tmatch := chunkMatches[0]","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/chunker/util.go#L108-L144","documentation":"parseNameToken reports this when the chunk name format pattern contains zero occurrences of the {name} token. The token is mandatory because the driver must embed the original file's base name into every chunk file name to be able to reassemble and identify the file.","triggerScenarios":"Configuring chunk_name_format as 'part_{chunk:03}' or 'file-{chunk}' — any pattern with a {chunk} token but no {name}. Thrown from setChunkNameFormat during Init, so the storage fails to come online.","commonSituations":"Users trying to shorten chunk file names; templates written from memory that omit {name}; misunderstanding that {name} is required, not optional.","solutions":["Add the {name} token to the pattern, e.g. '{name}_{chunk:03}'","Check for typos such as {filename}, {file}, or {Name} — only the exact literal {name} is recognized"],"exampleFix":"// before\nchunk_name_format: chunk_{chunk:03}\n// after\nchunk_name_format: {name}_chunk_{chunk:03}","handlingStrategy":"validation","validationCode":"if strings.Count(f, \"{name}\") != 1 {\n    return fmt.Errorf(\"chunk name format must contain exactly one {name} token: %q\", f)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat {name} as a required token in templates surfaced to users","Reject configs early instead of letting storage Init fail at runtime"],"tags":["chunker","configuration","validation"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}