Repository navigation
fix(go-document): keep upload partial success data as array - #16661
Conversation
📝 WalkthroughWalkthroughThe document upload handler now returns a server-error response for partial failures, with the error message joined into ChangesPartial Upload Error Response
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/handler/document.go (1)
972-996: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate inline JSON response construction — reuse
jsonResponse.Both branches (raw-files and mapped) manually build the same
gin.H{"code":..., "message":..., "data":...}envelope instead of using the existingjsonResponsehelper (seeinternal/handler/dataset.go), which already implements this exactcode, data, messagecontract and is used consistently elsewhere.♻️ Proposed refactor to reduce duplication
if strings.ToLower(c.DefaultQuery("return_raw_files", "false")) == "true" { if len(errMsgs) > 0 { - c.JSON(http.StatusOK, gin.H{ - "code": common.CodeServerError, - "message": strings.Join(errMsgs, "\n"), - "data": data, - }) + jsonResponse(c, common.CodeServerError, data, strings.Join(errMsgs, "\n")) return } jsonSuccess(c, data) return } mapped := make([]map[string]interface{}, len(data)) for i, d := range data { mapped[i] = mapDocKeysWithRunStatus(d) } if len(errMsgs) > 0 { - c.JSON(http.StatusOK, gin.H{ - "code": common.CodeServerError, - "message": strings.Join(errMsgs, "\n"), - "data": mapped, - }) + jsonResponse(c, common.CodeServerError, mapped, strings.Join(errMsgs, "\n")) return } jsonSuccess(c, mapped)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/document.go` around lines 972 - 996, The raw-files and mapped response branches in the document handler are duplicating the same JSON envelope instead of using the existing jsonResponse helper. Update the logic around the return_raw_files handling in document.go to route both the error and success responses through jsonResponse, matching the code/data/message contract already used in dataset.go. Keep the mapped data transformation with mapDocKeysWithRunStatus, but remove the inline gin.H construction so the response shape stays centralized and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/handler/document.go`:
- Around line 972-996: The raw-files and mapped response branches in the
document handler are duplicating the same JSON envelope instead of using the
existing jsonResponse helper. Update the logic around the return_raw_files
handling in document.go to route both the error and success responses through
jsonResponse, matching the code/data/message contract already used in
dataset.go. Keep the mapped data transformation with mapDocKeysWithRunStatus,
but remove the inline gin.H construction so the response shape stays centralized
and consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02b1c065-0527-4ace-b879-aefef66d29f3
📒 Files selected for processing (2)
internal/handler/document.gointernal/handler/document_test.go
Summary
Keep
dataas the uploaded document array when dataset document upload partially succeeds.This matches the Python API behavior and allows parse-on-creation to run for successfully uploaded files when other files in the same folder are unsupported.