t8y2/dbx · error

invalid params: %w

Error message

invalid params: %w

What it means

decodeParams unmarshals the raw JSON params into map[string]any; empty params or literal null are tolerated as an empty map, but anything that is not a valid JSON object produces this error wrapping the underlying json.Unmarshal failure. It surfaces when the params field is malformed or of the wrong JSON type (e.g. an array, string, or number instead of an object).

Source

Thrown at agents/drivers/rocketmq/server.go:150

		_ = a.client.Close()
	}
	if a.proxies != nil {
		a.proxies.Close()
	}
	a.client = nil
	a.proxies = nil
	a.connection = connectionConfig{}
	a.clusterName = ""
	a.brokerAddr = ""
}

func decodeParams(raw json.RawMessage) (map[string]any, error) {
	if len(raw) == 0 || string(raw) == "null" {
		return map[string]any{}, nil
	}
	var params map[string]any
	if err := json.Unmarshal(raw, &params); err != nil {
		return nil, fmt.Errorf("invalid params: %w", err)
	}
	return params, nil
}

func normalizeError(err error) string {
	if err == nil {
		return ""
	}
	message := strings.TrimSpace(err.Error())
	if message == "" {
		return "RocketMQ operation failed"
	}
	return message
}

func okResult() map[string]any {
	return map[string]any{"ok": true}
}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Validate the params JSON with a linter/parser before sending; ensure it is a JSON object
  2. Inspect the wrapped %w error message for the exact JSON syntax offset
  3. Fix the client serialization so params is map/object-shaped, not an array or string
  4. If params are genuinely optional, send null or omit the field rather than empty/garbage text

Example fix

// before
params := "{topic: demo}" // invalid JSON
// after
params := `{"topic":"demo"}`
Defensive patterns

Strategy: validation

Validate before calling

func validParams(raw string) bool {
    if raw == "" || raw == "null" {
        return true
    }
    var m map[string]any
    return json.Unmarshal([]byte(raw), &m) == nil
}
// call validParams(paramsJSON) before invoking the agent

Try / catch

res, err := agent.Call(ctx, method, json.RawMessage(raw))
if err != nil && strings.Contains(err.Error(), "invalid params:") {
    var syntaxErr *json.SyntaxTypeError
    if errors.As(err, &syntaxErr) {
        log.Printf("params JSON malformed: %v", syntaxErr)
    }
}

Prevention

When it happens

Trigger: Calling any dispatch method with params set to invalid JSON (e.g. '{"topic": }'), or a JSON non-object like '[1,2]', '"topic"', or '42'.

Common situations: Hand-crafted JSON with a syntax error; clients serializing params as an array instead of an object; double-encoded JSON strings (params passed as a quoted string); template interpolation producing invalid JSON.

Related errors


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