Tencent/WeKnora · error

http marshal read request: %w

Error message

http marshal read request: %w

What it means

Fired in Read when json.Marshal of the httpReadRequest body fails. The request struct only holds plain strings/byte slices, so this practically fires only if FileContent/base64 encoding yields an unmarshalable value or a custom marshaler errors; it aborts the document read submission before any HTTP call.

Source

Thrown at internal/infrastructure/docparser/weknoracloud_http_reader.go:90

		req.FileName, req.FileType, req.ParserEngine, strings.TrimSpace(req.URL) != "", len(req.FileContent), req.RequestID)
	body := httpReadRequest{
		FileName:  req.FileName,
		FileType:  req.FileType,
		URL:       req.URL,
		Title:     req.Title,
		RequestID: req.RequestID,
		Config: &httpReadConfig{
			ParserEngine:          req.ParserEngine,
			ParserEngineOverrides: req.ParserEngineOverrides,
		},
	}
	if len(req.FileContent) > 0 {
		body.FileContent = base64.StdEncoding.EncodeToString(req.FileContent)
	}
	jsonBody, err := json.Marshal(body)
	if err != nil {
		logger.Errorf(context.Background(), "[WeKnoraCloud] marshal read request: %v", err)
		return nil, fmt.Errorf("http marshal read request: %w", err)
	}
	httpReq, err := p.newSignedRequest(ctx, http.MethodPost, weKnoraCloudReaderBaseURL+"/reader", jsonBody)
	if err != nil {
		logger.Errorf(context.Background(), "[WeKnoraCloud] signed read request: %v", err)
		return nil, err
	}
	resp, err := p.client.Do(httpReq)
	if err != nil {
		logger.Errorf(context.Background(), "[WeKnoraCloud] http read request failed: %v", err)
		return nil, fmt.Errorf("http read failed: %w", err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK {
		bodyBytes, _ := io.ReadAll(resp.Body)
		logger.Errorf(context.Background(), "[WeKnoraCloud] http read unexpected status %d: %s", resp.StatusCode, string(bodyBytes))
		return nil, fmt.Errorf("http read status %d: %s", resp.StatusCode, string(bodyBytes))
	}
	var submit weKnoraCloudAsyncSubmitResponse

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the wrapped error to find which field failed to marshal
  2. Log req.RequestID and FileType to identify the offending document
  3. Retry once with a fresh request; marshal failures here are not transient in practice
  4. Report upstream if a supported FileType produces unmarshalable content
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/infrastructure/docparser/weknoracloud_http_reader.go:90 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/b717bfdb713c7f11. Report an issue: GitHub.