t8y2/dbx · error

ETCD_INVALID_%s

ETCD_INVALID_%s

Error message

ETCD_INVALID_%s: a positive integer is required

What it means

requiredPositiveLong validates that a numeric request field is present and strictly positive. When the field is missing, null, zero, negative, or not a number, it throws a typed error whose code embeds the uppercased field name (e.g. ETCD_INVALID_TTL). This keeps malformed lease/compact requests from reaching etcd.

Source

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

	return value
}

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

func requiredPositiveLong(params map[string]json.RawMessage, field string) (int64, error) {
	value := longOrNull(params, field)
	if value == nil || *value <= 0 {
		return 0, fmt.Errorf("ETCD_INVALID_%s: a positive integer is required", strings.ToUpper(field))
	}
	return *value, nil
}

func requiredString(params map[string]json.RawMessage, field string) (string, error) {
	value := stringOrNull(params, field)
	if value == nil || *value == "" {
		return "", fmt.Errorf("ETCD_%s_REQUIRED", strings.ToUpper(field))
	}
	return *value, nil
}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Inspect the error code (ETCD_INVALID_<FIELD>) to find the offending field and supply a positive integer JSON number (e.g. "TTL": 10).
  2. Add client-side validation: reject value <= 0 before issuing the call.
  3. If the field may legitimately be absent, use the optional variant instead of the required_* helper, or default it explicitly.
  4. Check for string-typed numbers in the request payload and convert them to JSON numbers.

Example fix

// before
{"TTL": 0} // or field omitted
// after
{"TTL": 300}
Defensive patterns

Strategy: validation

Validate before calling

func validatePositiveInt(params map[string]json.RawMessage, field string) error {
	raw, ok := params[field]
	if !ok {
		return fmt.Errorf("field %s is required", field)
	}
	var n int64
	if err := json.Unmarshal(raw, &n); err != nil {
		return fmt.Errorf("field %s must be a JSON number", field)
	}
	if n <= 0 {
		return fmt.Errorf("field %s must be > 0", field)
	}
	return nil
}

Try / catch

ttl, err := leaseGrant(params)
if err != nil {
	var typed interface{ Code() string }
	if errors.As(err, &typed) && strings.HasPrefix(typed.Code(), "ETCD_INVALID_") {
		return fmt.Errorf("bad request: %w", err) // 400-style, do not retry
	}
	return err
}

Prevention

When it happens

Trigger: leaseGet, leaseGrant, leaseKeepAlive, leaseRevoke, or compact called with params missing the required field, the field set to 0 or a negative number, or a non-numeric JSON value (longOrNull returns nil for non-numbers).

Common situations: Client omits "TTL" on a lease grant; a template variable interpolated as 0 or empty; sending "TTL": "10" as a string when a JSON number is required; default-initialized struct serialized with 0; compact called with rev=0.

Related errors


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