{"record":{"id":"17e20d0d549b73af","repo":"ipfs/kubo","slug":"cannot-specify-negative-resolve-cache-size","errorCode":null,"errorMessage":"cannot specify negative resolve cache size","messagePattern":"cannot specify negative resolve cache size","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/coreapi/coreapi.go","lineNumber":225,"sourceCode":"\t\t}\n\t\tif n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() {\n\t\t\treturn errors.New(\"cannot manually publish while IPNS is mounted\")\n\t\t}\n\t\treturn nil\n\t}\n\n\tcfg, err := n.Repo.Config()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif settings.Offline {\n\t\tcs := cfg.Ipns.ResolveCacheSize\n\t\tif cs == 0 {\n\t\t\tcs = node.DefaultIpnsCacheSize\n\t\t}\n\t\tif cs < 0 {\n\t\t\treturn nil, errors.New(\"cannot specify negative resolve cache size\")\n\t\t}\n\n\t\tnsOptions := []namesys.Option{\n\t\t\tnamesys.WithDatastore(subAPI.repo.Datastore()),\n\t\t\tnamesys.WithDNSResolver(subAPI.dnsResolver),\n\t\t\tnamesys.WithCache(cs),\n\t\t\tnamesys.WithMaxCacheTTL(cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL)),\n\t\t}\n\n\t\tsubAPI.routing = offlineroute.NewOfflineRouter(irouting.DHTValueDatastore(subAPI.repo.Datastore()), subAPI.recordValidator)\n\n\t\tsubAPI.namesys, err = namesys.NewNameSystem(subAPI.routing, nsOptions...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error constructing namesys: %w\", err)\n\t\t}\n\n\t\tsubAPI.peerstore = nil\n\t\tsubAPI.peerHost = nil","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreapi/coreapi.go#L207-L243","documentation":"When the node is constructed with `Ipns.Offline` mode, coreapi reads the configured IPNS resolve cache size (`Ipns.ResolveCacheSize`). A zero value means \"use the default\", but any negative value is nonsensical for a cache capacity, so WithOptions rejects the configuration up front instead of failing later inside namesys.","triggerScenarios":"Calling coreapi.NewNode(node, &coreapi.APIOptions{Offline: true}) when the repo config contains a negative Ipns.ResolveCacheSize, e.g. loaded from a hand-edited or programmatically generated config file.","commonSituations":"Users hand-editing the config JSON and setting Ipns.ResolveCacheSize to -1 to try to 'disable' the IPNS cache; provisioning scripts that compute the cache size (e.g. from memory) and overflow or miscalculate into a negative number.","solutions":["Set Ipns.ResolveCacheSize to 0 in the config to get the default (node.DefaultIpnsCacheSize).","Set Ipns.ResolveCacheSize to a positive integer sized for your workload.","Remove the Ipns.ResolveCacheSize key entirely so the default applies."],"exampleFix":"// before (config)\n\"Ipns\": { \"Offline\": true, \"ResolveCacheSize\": -1 }\n// after\n\"Ipns\": { \"Offline\": true, \"ResolveCacheSize\": 0 }","handlingStrategy":"validation","validationCode":"cfg, err := node.Repo.Config()\nif err != nil { return err }\nif cs := cfg.Ipns.ResolveCacheSize; cs < 0 {\n    return fmt.Errorf(\"Ipns.ResolveCacheSize must be >= 0, got %d\", cs)\n}","typeGuard":"func validResolveCacheSize(cs int) bool { return cs >= 0 }","tryCatchPattern":"n, err := coreapi.NewNode(node, opts)\nif errors.Is(err, errNegativeCache) || strings.Contains(err.Error(), \"negative resolve cache size\") {\n    // fix config or fall back to defaults\n}","preventionTips":["Never set Ipns.ResolveCacheSize to a negative number; use 0 for the default","Validate the generated config JSON before initializing a node in scripts","Clamp computed cache sizes to >= 0 in provisioning code"],"tags":["config","ipns","offline"],"backgroundTag":"negative-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"}