{"record":{"id":"7623cba70020de1b","repo":"AlistGo/alist","slug":"chunk-width-in-chunk-n-must-be-a-positive-intege","errorCode":null,"errorMessage":"chunk width in {chunk:N} must be a positive integer","messagePattern":"chunk width in (.+?) must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/chunker/util.go","lineNumber":150,"sourceCode":"\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]\n\tstart = match[0]\n\tend = match[1]\n\tif match[2] >= 0 && match[3] >= 0 {\n\t\twidth, err = strconv.Atoi(pattern[match[2]:match[3]])\n\t\tif err != nil || width <= 0 {\n\t\t\treturn 0, 0, 0, errors.New(\"chunk width in {chunk:N} must be a positive integer\")\n\t\t}\n\t}\n\treturn start, end, width, nil\n}\n\nfunc (d *Chunker) makeChunkName(filePath string, chunkNo int, xactID string) string {\n\tdir, baseName := path.Split(filePath)\n\tname := fmt.Sprintf(d.dataNameFmt, baseName, chunkNo+d.StartFrom)\n\tif xactID != \"\" {\n\t\tname += fmt.Sprintf(tempSuffixFormat, xactID)\n\t}\n\treturn dir + name\n}\n\nfunc (d *Chunker) parseChunkName(filePath string) (parentPath string, chunkNo int, ctrlType, xactID string) {\n\tdir, name := path.Split(filePath)\n\tmatch := d.nameRegexp.FindStringSubmatch(name)\n\tif match == nil || match[1] == \"\" {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/chunker/util.go#L132-L168","documentation":"The width N inside a {chunk:N} token failed strconv.Atoi or parsed to a value <= 0. The width sets the minimum zero-padding of chunk numbers in generated names (and the regex '[0-9]{N,}' used to find chunks), so it must be a positive decimal integer.","triggerScenarios":"chunk_name_format containing '{chunk:0}', '{chunk:-3}', '{chunk:abc}', or a huge number that overflows Atoi. Note the regexp only captures digits, so in practice this fires for '{chunk:0}' or an all-digit string that overflows int. Fails at init in parseChunkToken.","commonSituations":"Using 0 padding width by habit; negative widths copied from other tools; very large widths (e.g. 99999999999999999999) causing Atoi range errors.","solutions":["Use a positive width such as {chunk:03}, {chunk:05}","For no padding at all, use the plain {chunk} token instead of {chunk:0}","Keep widths modest (2–6 digits) so file names stay short and under the 255-byte metadata/name limits"],"exampleFix":"// before\nchunk_name_format: {name}_{chunk:0}\n// after\nchunk_name_format: {name}_{chunk:03}","handlingStrategy":"validation","validationCode":"var widthRe = regexp.MustCompile(`^\\{chunk:([0-9]+)\\}$`)\nif m := widthRe.FindStringSubmatch(token); m != nil {\n    w, _ := strconv.Atoi(m[1])\n    if w <= 0 {\n        return fmt.Errorf(\"chunk width must be positive, got %d\", w)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use {chunk} with no width when padding is not wanted, never {chunk:0}","Bound widths to 1-6 in config UIs to also keep names short"],"tags":["chunker","configuration","validation"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}