t8y2/dbx · error

Key is required

Error message

Key is required

What it means

keyBytesParam is the shared parameter decoder for all key-based kv operations (get, put, delete, rename, history, authRolePermission). It requires a "key" parameter that unmarshals into a JSON string; if the parameter is missing or is not a string, it returns the plain error "Key is required". This is a client-side request-validation error, raised before any network call to etcd.

Source

Thrown at agents/drivers/etcd-go/kv.go:496

	return base64.StdEncoding.EncodeToString(next)
}

func keyBytesParam(params map[string]json.RawMessage) (string, error) {
	if encoded := rawObject(params, "keyBytes"); encoded != nil {
		value, err := parseValueObject(encoded)
		if err != nil {
			return "", err
		}
		return value, nil
	}
	if raw, ok := params["key"]; ok && raw != nil && string(raw) != "null" {
		var key string
		if err := json.Unmarshal(raw, &key); err != nil {
			return "", err
		}
		return key, nil
	}
	return "", errors.New("Key is required")
}

func rawObject(params map[string]json.RawMessage, key string) map[string]json.RawMessage {
	raw := params[key]
	if len(raw) == 0 || string(raw) == "null" {
		return nil
	}
	var object map[string]json.RawMessage
	if err := json.Unmarshal(raw, &object); err != nil || object == nil {
		return nil
	}
	return object
}

func bytesObject(bytes []byte) map[string]any {
	return map[string]any{
		"encoding": "base64",
		"data":     base64.StdEncoding.EncodeToString(bytes),

View on GitHub (pinned to c0390bff16)

Solutions

  1. Include a "key" field as a JSON string in the params of the kv call.
  2. Verify the parameter is spelled exactly "key" and is quoted as a JSON string, not a number or object.
  3. Validate/serialize params before dispatch (e.g. marshal a struct with a required Key string field).

Example fix

// before: missing/wrong-typed key
agent.call("get", {"k": 42})

// after: required string key
agent.call("get", {"key": "cfg/a"})
Defensive patterns

Strategy: validation

Validate before calling

func requireKey(params map[string]any) (string, error) {
    k, ok := params["key"]
    if !ok { return "", errors.New("params.key is required") }
    s, isStr := k.(string)
    if !isStr || s == "" { return "", errors.New("params.key must be a non-empty string") }
    return s, nil
}

Type guard

func keyParam(v any) (string, bool) {
    s, ok := v.(string)
    return s, ok && s != ""
}

Prevention

When it happens

Trigger: Calling any of get/put/delete/rename/history/authRolePermission without a "key" field in params, with key set to null, or with a non-string JSON value (number, object, array) at kv.go:496.

Common situations: Typo in the parameter name (e.g. sending "k" or "name" instead of "key"); passing a raw (unquoted) string through a JSON layer that then fails to unmarshal into string; building params programmatically and forgetting the key field.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/25efb09dbba362ec. Report an issue: GitHub.