cilium/cilium · error

cannot assign value=%s for key=%s, expected type=%s: %w

Error message

cannot assign value=%s for key=%s, expected type=%s: %w

What it means

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.

Source

Thrown at hubble/cmd/config/set.go:82

		newVal, err = cast.ToBoolE(val)
	case "duration":
		newVal, err = cast.ToDurationE(val)
	case "int":
		newVal, err = cast.ToIntE(val)
	case "string":
		newVal = val
	case "stringSlice":
		val = strings.TrimSuffix(strings.TrimPrefix(val, "["), "]")
		if val == "" {
			newVal = []string{} // csv reader would return io.EOF
		} else {
			newVal, err = csv.NewReader(strings.NewReader(val)).Read()
		}
	default:
		return fmt.Errorf("unhandled type %s, please open an issue", typ)
	}
	if err != nil {
		return fmt.Errorf("cannot assign value=%s for key=%s, expected type=%s: %w", value, key, typ, err)
	}

	// Create a file-only viper config from the configured file to avoid
	// writing defaults and/or values set via environment variables or flags.
	// This viper config is only used to write the resulting config.
	// This method also prevents from writing default values for all keys
	// therefore only writing key/value pairs explicitly set by the caller.
	configPath := vp.GetString(config.KeyConfig)
	fileVP, err := newFileOnlyViper(configPath)
	if err != nil {
		return err
	}
	fileVP.Set(key, newVal)
	return fileVP.WriteConfigAs(configPath)
}

// newFileOnlyViper creates a new viper config that only reads from the given
// configuration file and is not bound to any environment variable or flag.

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Read the expected type from the message and supply a conforming value (e.g. `true`, `42`, `a,b,c`)
  2. Run `hubble config set --help` to check each key's flag type
  3. Quote list values in the shell: hubble config set sort "time,src"
  4. Reset the key with `hubble config reset <key>` if unsure of defaults

Example fix

// before
hubble config set debug yes
// after
hubble config set debug true
Defensive patterns

Strategy: validation

Validate before calling

// validate before calling set
switch key {
case "debug":
	if _, err := strconv.ParseBool(value); err != nil { return fmt.Errorf("debug expects true/false") }
case "retry-timeout":
	if _, err := strconv.Atoi(value); err != nil { return fmt.Errorf("retry-timeout expects an integer") }
}

Type guard

func isParsableAsBool(s string) bool {
	_, err := strconv.ParseBool(s)
	return err == nil
}

Try / catch

if err := runSet(cmd, vp, key, value); err != nil {
	var msg string
	if strings.Contains(err.Error(), "cannot assign value") { msg = "check the value's type: " + err.Error() }
	return errors.New(msg)
}

Prevention

When it happens

Trigger: `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.

Common situations: Quoting issues in shell turning lists into single strings; setting numeric keys with units like `10s`; forgetting that bool keys need `true`/`false`.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/0f2a1f7df77a7514. Report an issue: GitHub.