{"record":{"id":"d85535889da2898c","repo":"ipfs/kubo","slug":"import-batchmaxsize-must-be-positive-got-d","errorCode":null,"errorMessage":"Import.BatchMaxSize must be positive, got %d","messagePattern":"Import\\.BatchMaxSize must be positive, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/import.go","lineNumber":128,"sourceCode":"\t\t// Valid values are powers of 2 between 8 and 1024: 8, 16, 32, 64, 128, 256, 512, 1024\n\t\tif fanout < 8 || !isPowerOfTwo(fanout) || fanout > 1024 {\n\t\t\treturn fmt.Errorf(\"Import.UnixFSHAMTDirectoryMaxFanout must be a power of 2, between 8 and 1024 (got %d)\", fanout)\n\t\t}\n\t}\n\n\t// Validate BatchMaxNodes\n\tif !cfg.BatchMaxNodes.IsDefault() {\n\t\tmaxNodes := cfg.BatchMaxNodes.WithDefault(DefaultBatchMaxNodes)\n\t\tif maxNodes <= 0 {\n\t\t\treturn fmt.Errorf(\"Import.BatchMaxNodes must be positive, got %d\", maxNodes)\n\t\t}\n\t}\n\n\t// Validate BatchMaxSize\n\tif !cfg.BatchMaxSize.IsDefault() {\n\t\tmaxSize := cfg.BatchMaxSize.WithDefault(DefaultBatchMaxSize)\n\t\tif maxSize <= 0 {\n\t\t\treturn fmt.Errorf(\"Import.BatchMaxSize must be positive, got %d\", maxSize)\n\t\t}\n\t}\n\n\t// Validate UnixFSChunker format\n\tif !cfg.UnixFSChunker.IsDefault() {\n\t\tchunker := cfg.UnixFSChunker.WithDefault(DefaultUnixFSChunker)\n\t\tif !isValidChunker(chunker) {\n\t\t\treturn fmt.Errorf(\"Import.UnixFSChunker invalid format: %q (expected \\\"size-<bytes>\\\", \\\"rabin-<min>-<avg>-<max>\\\", or \\\"buzhash\\\")\", chunker)\n\t\t}\n\t}\n\n\t// Validate HashFunction\n\tif !cfg.HashFunction.IsDefault() {\n\t\thashFunc := cfg.HashFunction.WithDefault(DefaultHashFunction)\n\t\thashCode, ok := mh.Names[strings.ToLower(hashFunc)]\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"Import.HashFunction unrecognized: %q\", hashFunc)\n\t\t}","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/config/import.go#L110-L146","documentation":"ValidateImportConfig requires Import.BatchMaxSize, the maximum cumulative byte size of an add batch before it is flushed, to be strictly positive after defaults. A non-positive batch size makes the batching logic invalid, so startup or import aborts with this error.","triggerScenarios":"Setting Import.BatchMaxSize to 0 or a negative byte count in the config and running the daemon or an import.","commonSituations":"Hand-edited configs with 0 assumed to mean 'no limit'; size computations in scripts yielding 0 (e.g. unit conversion mistakes); copied example configs with placeholders.","solutions":["Set Import.BatchMaxSize to a positive byte value (e.g. 1<<27) or remove it for the default","Verify unit conversions in scripts that compute the size (MiB/GiB)","Keep BatchMaxSize consistent with BatchMaxNodes when tuning"],"exampleFix":"// before\n{\"Import\": {\"BatchMaxSize\": 0}}\n// after\n{\"Import\": {\"BatchMaxSize\": 134217728}}","handlingStrategy":"validation","validationCode":"v := importCfg.BatchMaxSize.WithDefault(config.DefaultBatchMaxSize)\nif v <= 0 {\n\treturn fmt.Errorf(\"Import.BatchMaxSize must be positive, got %d\", v)\n}","typeGuard":null,"tryCatchPattern":"if err := config.ValidateImportConfig(&importCfg); err != nil {\n\tif strings.Contains(err.Error(), \"BatchMaxSize must be positive\") {\n\t\timportCfg.BatchMaxSize = config.DefaultBatchMaxSize\n\t\terr = config.ValidateImportConfig(&importCfg)\n\t}\n\treturn err\n}","preventionTips":["Use explicit byte literals (e.g. 1<<27) to avoid unit-conversion mistakes","Omit the key for defaults instead of writing 0","Validate generated configs before deploying them to nodes"],"tags":["config","import","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}