go-kratos/kratos · info

no field path

Error message

no field path

What it means

'no field path' (encoding/form/proto_decode.go:39) is a defensive guard at the top of populateFieldValues: it fires when fieldPath has fewer than one element. In the public entry point DecodeValues, keys are built with strings.Split(key, ".") which always returns at least one element (even for the empty string you get [""]), and the internal recursions pass fieldPath[1:] only from paths of length >= 2 or the fixed []string{fieldPath[1]}. So through supported API surface this error is effectively unreachable; hitting it means the unexported helper was called with an empty slice (forks, tests, or refactors of the package).

Source

Thrown at encoding/form/proto_decode.go:39

)

const fieldSeparator = "."

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 {

View on GitHub (pinned to 668db92c2c)

Solutions

  1. If you forked or reflect into this package, ensure fieldPath always contains at least one segment before calling
  2. In public usage, treat this error as a bug report - file it upstream with the exact query that produced it
  3. Audit any local preprocessing of query keys (splitting, trimming) so it never yields an empty slice
Defensive patterns

Strategy: validation

Validate before calling

// guard any local preprocessing before calling the codec
if len(segments) == 0 {
    return fmt.Errorf("empty field path from key %q", rawKey)
}

Prevention

When it happens

Trigger: Direct internal invocation populateFieldValues(msg, []string{}, values) in modified/forked copies of encoding/form; a refactor that introduces a trimming step producing an empty path slice; goptest plumbing that calls the unexported function via package-internal tests.

Common situations: Vendored/forked kratos form codec modified locally; custom query-key preprocessing inserted before populateFieldValues that can return zero segments; version drift where a caller contract changed but this guard stayed.

Related errors


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