Tencent/WeKnora · error

marshal request body

Error message

marshal request body: %w

What it means

json.Marshal of the outgoing Notion API request body failed in doRequest. Since bodies are struct/map values built in code, this indicates an unsupported type (e.g. channel, func, or cyclic data) was passed as the request body.

Solutions

  1. Check the body argument for unsupported value types
  2. Ensure nested values are JSON-serializable structs/maps
  3. Marshal the body once at construction to fail fast
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/datasource/connector/notion/client.go:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/60bee9a1b7bc3ba8. Report an issue: GitHub.

Appendix: source

Thrown at internal/datasource/connector/notion/client.go:69

	select {
	case <-t.C:
		return nil
	case <-ctx.Done():
		return ctx.Err()
	}
}

// doRequest performs an authenticated, rate-limited HTTP request to the Notion API.
func (c *notionClient) doRequest(ctx context.Context, method, path string, body interface{}) ([]byte, error) {
	if err := c.limiter.Wait(ctx); err != nil {
		return nil, fmt.Errorf("rate limiter: %w", err)
	}

	var bodyReader io.Reader
	if body != nil {
		bodyBytes, err := json.Marshal(body)
		if err != nil {
			return nil, fmt.Errorf("marshal request body: %w", err)
		}
		bodyReader = bytes.NewReader(bodyBytes)
	}

	req, err := http.NewRequestWithContext(ctx, method, c.baseURL+path, bodyReader)
	if err != nil {
		return nil, fmt.Errorf("create request: %w", err)
	}
	req.Header.Set("Authorization", "Bearer "+c.token)
	req.Header.Set("Notion-Version", NotionAPIVersion)
	req.Header.Set("Content-Type", "application/json")

	var lastErr error
	for attempt := 0; attempt <= maxRetries; attempt++ {
		if attempt > 0 {
			if body != nil {
				bodyBytes, _ := json.Marshal(body)
				req.Body = io.NopCloser(bytes.NewReader(bodyBytes))

View on GitHub (pinned to 988cbb0330)