{"record":{"id":"3c76e7e24d518ebc","repo":"ipfs/kubo","slug":"dht-timeout-value-must-be-0","errorCode":null,"errorMessage":"DHT timeout value must be >= 0","messagePattern":"DHT timeout value must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/name/ipns.go","lineNumber":119,"sourceCode":"\t\tstream, _ := req.Options[streamOptionName].(bool)\n\n\t\topts := []options.NameResolveOption{\n\t\t\toptions.Name.Cache(!nocache),\n\t\t}\n\n\t\tif !recursive {\n\t\t\topts = append(opts, options.Name.ResolveOption(namesys.ResolveWithDepth(1)))\n\t\t}\n\t\tif rcok {\n\t\t\topts = append(opts, options.Name.ResolveOption(namesys.ResolveWithDhtRecordCount(rc)))\n\t\t}\n\t\tif dhttok {\n\t\t\td, err := time.ParseDuration(dhtt)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif d < 0 {\n\t\t\t\treturn errors.New(\"DHT timeout value must be >= 0\")\n\t\t\t}\n\t\t\topts = append(opts, options.Name.ResolveOption(namesys.ResolveWithDhtTimeout(d)))\n\t\t}\n\n\t\tif !stream {\n\t\t\toutput, err := api.Name().Resolve(req.Context, name, opts...)\n\t\t\tif err != nil && (recursive || err != namesys.ErrResolveRecursion) {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tpth, err := path.NewPath(output.String())\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\treturn cmds.EmitOnce(res, &ResolvedPath{pth.String()})\n\t\t}\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/name/ipns.go#L101-L137","documentation":"`ipfs ipns resolve --dht-timeout` rejects negative durations. When --dht-record / dht options are used, the parsed duration is validated to be non-negative because a negative DHT lookup timeout is meaningless. The value is later passed to namesys.ResolveWithDhtTimeout.","triggerScenarios":"Running `ipfs ipns resolve --dht-record --dht-timeout=-5s` or any negative duration string accepted by time.ParseDuration (e.g. '-1m').","commonSituations":"Scripted invocations computing the timeout from a difference that came out negative, or a typo placing the minus sign in the flag value.","solutions":["Pass a non-negative duration, e.g. --dht-timeout=30s or --dht-timeout=0 for no wait","Fix the script that computes the duration so it clamps to >= 0"],"exampleFix":"// before\nipfs ipns resolve --dht-record --dht-timeout=-5s /ipns/example\n// error: DHT timeout value must be >= 0\n// after\nipfs ipns resolve --dht-record --dht-timeout=5s /ipns/example","handlingStrategy":"validation","validationCode":"d, err := time.ParseDuration(flagValue)\nif err != nil || d < 0 {\n    return fmt.Errorf(\"dht-timeout must be a non-negative duration, got %q\", flagValue)\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"DHT timeout value must be >= 0\") {\n    // clamp the computed duration to 0 and retry\n}","preventionTips":["Clamp computed durations: if d < 0 { d = 0 }","Avoid literal negative durations in scripts"],"tags":["cli","ipns","validation"],"backgroundTag":"invalid-duration","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"}