{"record":{"id":"415e242b7c8150ca","repo":"ipfs/kubo","slug":"import-batchmaxnodes-must-be-positive-got-d","errorCode":null,"errorMessage":"Import.BatchMaxNodes must be positive, got %d","messagePattern":"Import\\.BatchMaxNodes must be positive, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/import.go","lineNumber":120,"sourceCode":"\t\t\treturn fmt.Errorf(\"Import.UnixFSDirectoryMaxLinks must be non-negative, got %d\", maxLinks)\n\t\t}\n\t}\n\n\t// Validate UnixFSHAMTDirectoryMaxFanout if set\n\tif !cfg.UnixFSHAMTDirectoryMaxFanout.IsDefault() {\n\t\tfanout := cfg.UnixFSHAMTDirectoryMaxFanout.WithDefault(DefaultUnixFSHAMTDirectoryMaxFanout)\n\n\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}","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/config/import.go#L102-L138","documentation":"ValidateImportConfig requires Import.BatchMaxNodes, the maximum number of nodes buffered in an add batch before flush, to be strictly positive after defaults. A zero or negative batch capacity would prevent the importer from accumulating any nodes.","triggerScenarios":"Setting Import.BatchMaxNodes to 0 or a negative value in the config and starting the daemon or running `ipfs add`.","commonSituations":"Hand-edited configs where 0 was assumed to mean 'unbounded'; scripted config generation with failed arithmetic; tuning add performance with invalid values.","solutions":["Set Import.BatchMaxNodes to a positive integer (e.g. 128) or remove it for the default","Fix any script computing the value so it clamps to >= 1","Cross-check related Import.BatchMaxSize to keep the batch parameters consistent"],"exampleFix":"// before\n{\"Import\": {\"BatchMaxNodes\": 0}}\n// after\n{\"Import\": {\"BatchMaxNodes\": 128}}","handlingStrategy":"validation","validationCode":"v := importCfg.BatchMaxNodes.WithDefault(config.DefaultBatchMaxNodes)\nif v <= 0 {\n\treturn fmt.Errorf(\"Import.BatchMaxNodes must be positive, got %d\", v)\n}","typeGuard":null,"tryCatchPattern":"if err := config.ValidateImportConfig(&importCfg); err != nil {\n\tif strings.Contains(err.Error(), \"BatchMaxNodes must be positive\") {\n\t\timportCfg.BatchMaxNodes = config.DefaultBatchMaxNodes\n\t\terr = config.ValidateImportConfig(&importCfg)\n\t}\n\treturn err\n}","preventionTips":["Omit the key for defaults instead of writing 0","Clamp generated values to >= 1","Tune BatchMaxNodes and BatchMaxSize together and re-run validation after changes"],"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"}