Tencent/WeKnora · error

failed to marshal entries: %w

Error message

failed to marshal entries: %w

What it means

Thrown when json.Marshal fails to serialize the FAQ entries payload before uploading it to object storage (large-batch path, >200 entries). Only fires if an entry contains a value Go's encoding/json cannot encode, e.g. a channel, func, or cyclic reference in FAQEntryPayload.

Source

Thrown at internal/application/service/knowledge_faq_import.go:153

		DryRun:      payload.DryRun,
		EnqueuedAt:  enqueuedAt,
		InstanceID:  instanceID,
		Initiator:   types.TaskInitiatorFromContext(ctx),
	}

	// 阈值:超过 200 条或序列化后超过 50KB 时使用对象存储
	const (
		entryCountThreshold  = 200
		payloadSizeThreshold = 50 * 1024 // 50KB
	)

	entryCount := len(payload.Entries)
	if entryCount > entryCountThreshold {
		// 数据量较大,上传到对象存储
		entriesData, err := json.Marshal(payload.Entries)
		if err != nil {
			logger.Errorf(ctx, "Failed to marshal FAQ entries: %v", err)
			return "", fmt.Errorf("failed to marshal entries: %w", err)
		}

		logger.Infof(ctx, "FAQ entries size: %d bytes, uploading to object storage", len(entriesData))

		// 上传到私有桶(主桶),任务处理完成后清理
		fileName := fmt.Sprintf("faq_import_entries_%s_%d.json", taskID, enqueuedAt)
		entriesURL, err := s.fileSvc.SaveBytes(ctx, entriesData, tenantID, fileName, false)
		if err != nil {
			logger.Errorf(ctx, "Failed to upload FAQ entries to object storage: %v", err)
			return "", fmt.Errorf("failed to upload entries: %w", err)
		}

		logger.Infof(ctx, "FAQ entries uploaded to: %s", entriesURL)
		taskPayload.EntriesURL = entriesURL
		taskPayload.EntryCount = entryCount
	} else {
		// 数据量较小,直接存储在 payload 中
		taskPayload.Entries = payload.Entries

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the wrapped marshal error to find the offending entry/field
  2. Ensure FAQEntryPayload only contains JSON-serializable types (strings, ints, bools, slices)
  3. Reject malformed entries at API validation time before import
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/application/service/knowledge_faq_import.go:153 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/9bc494e1803d68cb. Report an issue: GitHub.