Tencent/WeKnora · error
decode extract_result object: %w
Error message
decode extract_result object: %w
What it means
The extract_result field did not start with '[', so the library decodes it as a single extractResultItem object; that object decode failed (mineru_cloud_converter.go:321). This means the doubly-encoded JSON inside extract_result is neither a valid single item object nor (per 853) a valid array. Usually the payload is malformed or the schema diverged from extractResultItem.
Source
Thrown at internal/infrastructure/docparser/mineru_cloud_converter.go:321
logger.Infof(context.Background(), "[MinerUCloud] Raw extract_result: %s", rawExtract)
}
// Pretty-print the structure to reveal all available fields
var rawObj interface{}
if err := json.Unmarshal(pollResp.Data.ExtractResult, &rawObj); err == nil {
logResponseStructure("MinerUCloud", rawObj, "extract_result")
}
// The extract_result can be either a single object or an array
var items []extractResultItem
if pollResp.Data.ExtractResult[0] == '[' {
if err := json.Unmarshal(pollResp.Data.ExtractResult, &items); err != nil {
return nil, fmt.Errorf("decode extract_result array: %w", err)
}
} else {
var single extractResultItem
if err := json.Unmarshal(pollResp.Data.ExtractResult, &single); err != nil {
return nil, fmt.Errorf("decode extract_result object: %w", err)
}
items = []extractResultItem{single}
}
return items, nil
}
// extractDoneResult extracts markdown and images from a completed batch item.
// Prefers inline markdown/content fields; falls back to downloading full_zip_url.
func (c *MinerUCloudReader) extractDoneResult(_ context.Context, item *extractResultItem) (string, []types.ImageRef, error) {
text := firstNonEmpty(item.Markdown, item.Content, item.Text)
if text != "" {
logger.Infof(context.Background(), "[MinerUCloud] parsed (inline), length=%d", len(text))
return text, nil, nil
}
if item.FullZipURL == "" {
return "", nil, fmt.Errorf("MinerU Cloud state=done but no markdown/content or full_zip_url")View on GitHub (pinned to 988cbb0330)
Solutions
- Log the raw extract_result string to see the actual shape returned.
- Update extractResultItem to match the current MinerU Cloud response schema.
- Add a fallback decode into json.RawMessage / map[string]any to introspect unknown shapes instead of failing outright.
- Verify you are using a compatible MinerU Cloud API version/endpoint.
Example fix
// before
var single extractResultItem
if err := json.Unmarshal(pollResp.Data.ExtractResult, &single); err != nil {
return nil, fmt.Errorf("decode extract_result object: %w", err)
}
// after — log the payload for diagnosis
var single extractResultItem
if err := json.Unmarshal(pollResp.Data.ExtractResult, &single); err != nil {
return nil, fmt.Errorf("decode extract_result object: %w (payload: %.300s)", err, string(pollResp.Data.ExtractResult))
} Defensive patterns
Strategy: type-guard
Validate before calling
var raw any
if err := json.Unmarshal(pollResp.Data.ExtractResult, &raw); err != nil {
return fmt.Errorf("extract_result is not valid JSON: %w", err)
}
if _, ok := raw.(map[string]any); !ok {
return errors.New("extract_result is not a JSON object")
} Type guard
func isExtractResultObject(raw json.RawMessage) bool {
var obj map[string]json.RawMessage
return json.Unmarshal(raw, &obj) == nil
} Try / catch
items, err := pollBatchResult(ctx, batchID)
if err != nil {
if strings.Contains(err.Error(), "decode extract_result object") {
// introspect payload; report contract mismatch
return fmt.Errorf("unexpected extract_result shape: %w", err)
}
return err
} Prevention
- Decode into map[string]any first to inspect unknown shapes before binding to a struct.
- Watch for MinerU Cloud API field renames (full_zip_url, markdown, state).
- Add a regression test that decodes a captured real response.
When it happens
Trigger: fetchBatchStatus receives extract_result that is neither '['-prefixed nor a JSON object matching extractResultItem — e.g. a quoted plain string, an object with renamed fields, or corrupted doubly-encoded JSON.
Common situations: MinerU Cloud returning a failure/status-only object without the expected fields plus changed types; API upgrades changing field names (e.g. full_zip_url moved); mocking/stub environments returning simplified payloads.
Related errors
- decode extract_result array: %w
- decode poll response: %w
- failed to decode API response: %w
- failed to set FAQ metadata: %w
- unmarshal page: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/bb7b1a9978d3d706.
Report an issue: GitHub.