{"record":{"id":"0f2a1f7df77a7514","repo":"cilium/cilium","slug":"cannot-assign-value-s-for-key-s-expected-type","errorCode":null,"errorMessage":"cannot assign value=%s for key=%s, expected type=%s: %w","messagePattern":"cannot assign value=(.+?) for key=(.+?), expected type=(.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hubble/cmd/config/set.go","lineNumber":82,"sourceCode":"\t\tnewVal, err = cast.ToBoolE(val)\n\tcase \"duration\":\n\t\tnewVal, err = cast.ToDurationE(val)\n\tcase \"int\":\n\t\tnewVal, err = cast.ToIntE(val)\n\tcase \"string\":\n\t\tnewVal = val\n\tcase \"stringSlice\":\n\t\tval = strings.TrimSuffix(strings.TrimPrefix(val, \"[\"), \"]\")\n\t\tif val == \"\" {\n\t\t\tnewVal = []string{} // csv reader would return io.EOF\n\t\t} else {\n\t\t\tnewVal, err = csv.NewReader(strings.NewReader(val)).Read()\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"unhandled type %s, please open an issue\", typ)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot assign value=%s for key=%s, expected type=%s: %w\", value, key, typ, err)\n\t}\n\n\t// Create a file-only viper config from the configured file to avoid\n\t// writing defaults and/or values set via environment variables or flags.\n\t// This viper config is only used to write the resulting config.\n\t// This method also prevents from writing default values for all keys\n\t// therefore only writing key/value pairs explicitly set by the caller.\n\tconfigPath := vp.GetString(config.KeyConfig)\n\tfileVP, err := newFileOnlyViper(configPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfileVP.Set(key, newVal)\n\treturn fileVP.WriteConfigAs(configPath)\n}\n\n// newFileOnlyViper creates a new viper config that only reads from the given\n// configuration file and is not bound to any environment variable or flag.","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/hubble/cmd/config/set.go#L64-L100","documentation":"When the string value cannot be converted into the flag's expected type (e.g. `true` for an int key, invalid CSV for a string slice), the underlying strconv/csv error is wrapped and returned with the offending value, key, and expected type.","triggerScenarios":"`hubble config set <key> <value>` where value fails parsing for the key's type: non-boolean for a bool key, non-integer for an int key, malformed list for a stringSlice key.","commonSituations":"Quoting issues in shell turning lists into single strings; setting numeric keys with units like `10s`; forgetting that bool keys need `true`/`false`.","solutions":["Read the expected type from the message and supply a conforming value (e.g. `true`, `42`, `a,b,c`)","Run `hubble config set --help` to check each key's flag type","Quote list values in the shell: hubble config set sort \"time,src\"","Reset the key with `hubble config reset <key>` if unsure of defaults"],"exampleFix":"// before\nhubble config set debug yes\n// after\nhubble config set debug true","handlingStrategy":"validation","validationCode":"// validate before calling set\nswitch key {\ncase \"debug\":\n\tif _, err := strconv.ParseBool(value); err != nil { return fmt.Errorf(\"debug expects true/false\") }\ncase \"retry-timeout\":\n\tif _, err := strconv.Atoi(value); err != nil { return fmt.Errorf(\"retry-timeout expects an integer\") }\n}","typeGuard":"func isParsableAsBool(s string) bool {\n\t_, err := strconv.ParseBool(s)\n\treturn err == nil\n}","tryCatchPattern":"if err := runSet(cmd, vp, key, value); err != nil {\n\tvar msg string\n\tif strings.Contains(err.Error(), \"cannot assign value\") { msg = \"check the value's type: \" + err.Error() }\n\treturn errors.New(msg)\n}","preventionTips":["Check flag type via `hubble config set --help` before setting","Quote list values: \"a,b,c\"","Use true/false, never yes/no, for bool keys"],"tags":["cli","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}