go-kratos/kratos · info

no value provided

Error message

no value provided

What it means

'no value provided' (encoding/form/proto_decode.go:42) is the second defensive guard in populateFieldValues: it fires when the values slice is empty. url.Values (the only input to the public DecodeValues) maps every key to a slice with at least one element - even 'a=' yields [""] - so through the supported API this cannot trigger. As with the field-path guard, it exists to protect internal invariants for direct callers of the unexported helper (forks, tests, refactors).

Source

Thrown at encoding/form/proto_decode.go:42

var errInvalidFormatMapKey = errors.New("invalid formatting for map key")

// DecodeValues decode url value into proto message.
func DecodeValues(msg proto.Message, values url.Values) error {
	for key, values := range values {
		if err := populateFieldValues(msg.ProtoReflect(), strings.Split(key, "."), values); err != nil {
			return err
		}
	}
	return nil
}

func populateFieldValues(v protoreflect.Message, fieldPath []string, values []string) error {
	if len(fieldPath) < 1 {
		return errors.New("no field path")
	}
	if len(values) < 1 {
		return errors.New("no value provided")
	}

	var fd protoreflect.FieldDescriptor
	for i, fieldName := range fieldPath {
		if fd = getFieldDescriptor(v, fieldName); fd == nil {
			// ignore unexpected field.
			return nil
		}
		if fd.IsMap() && len(fieldPath) == 2 {
			return populateMapField(fd, v.Mutable(fd).Map(), fieldPath, values)
		}
		if i == len(fieldPath)-1 {
			break
		}
		if fd.Message() == nil || fd.Cardinality() == protoreflect.Repeated {
			if fd.IsMap() && len(fieldPath) > 1 {
				// post subfield
				return populateMapField(fd, v.Mutable(fd).Map(), []string{fieldPath[1]}, values)

View on GitHub (pinned to 668db92c2c)

Solutions

  1. If you maintain a fork, guarantee at least one value string per field path before invoking the helper
  2. In public usage, report it upstream with the exact url.Values that triggered it - it indicates a package bug
  3. Avoid pre-filtering values slices to empty; keep the original 'a=' empty-string entry
Defensive patterns

Strategy: validation

Validate before calling

// guard any local preprocessing before calling the codec
if len(vals) == 0 {
    return fmt.Errorf("no values for key %q", key)
}

Prevention

When it happens

Trigger: Internal/direct calls of populateFieldValues(msg, path, []string{}) or nil values; a modified copy of the codec where a caller filters out empty strings before passing values; reflect-based test harnesses reaching into the package.

Common situations: Locally forked or rewritten form codec; a refactor that pre-cleans values (e.g. dropping empties) introducing a zero-length slice; copying test cases from proto_decode_test.go that exercise internals directly.

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/9a3709bdb98a7adc. Report an issue: GitHub.