Skip to content

Go: Update response message - #16803

Merged
JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix532
Jul 10, 2026
Merged

JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix532

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

As title.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd5f6263-0722-4e18-97cd-dccea15397c8

📥 Commits

Reviewing files that changed from the base of the PR and between a58b9ea and 9236726.

📒 Files selected for processing (2)
  • internal/service/agent.go
  • internal/service/chat_rest_update_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/agent.go

📝 Walkthrough

Walkthrough

This PR changes response helpers and handler call sites to use typed ErrorCode values directly, standardizes selected success responses through SuccessWithData, updates agent DSL normalization, and revises chat validation messages and service checks.

Changes

Response-code migration

Layer / File(s) Summary
Typed response contract
internal/common/response.go
Response payload code fields and ErrorWithCode now use ErrorCode directly.
Handler error-code migration
internal/admin/*, internal/handler/*
Error responses pass typed codes directly without int(...) conversions.
Success envelopes and wiring
internal/handler/*, internal/router/router.go, cmd/ragflow_server.go
Selected success responses use SuccessWithData; route, MCP, and local naming is normalized.
Service normalization and chat validation
internal/service/agent.go, internal/service/chat.go, internal/service/chat_rest_update_test.go
DSL values are passed directly to normalization helpers, while chat validation, tenant checks, messages, and related assertions are updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested labels: ☯️ refactor

Suggested reviewers: yuzhichang, yingfeng, Haruko386

Poem

A bunny trims each cast away,
Typed codes hop in neat array.
DSL maps dance through the night,
Chat errors now read just right.
Shared success blooms bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the PR, but it is too vague to convey the main change clearly. Rename it to something specific, such as standardizing Go response helpers and error code handling.
Description check ❓ Inconclusive The description matches the template heading, but 'As title.' is too generic and lacks the required summary context. Replace it with a brief summary of the response helper and error-code changes, plus any needed background context.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN
JinHai-CN marked this pull request as ready for review July 10, 2026 04:47
@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 10, 2026
Signed-off-by: Jin Hai <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/admin/enterprise_handler.go (1)

1530-1536: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Missing return after error response in ListUsersQuota.

Line 1534 sends an error response when top parsing fails but does not return. Execution continues to h.service.ListUsersQuota and potentially common.SuccessWithData, writing a second response body. This corrupts the HTTP response for any request with an invalid top parameter.

🐛 Proposed fix: add missing return
 	if topStr != "" {
 		top, err = strconv.Atoi(topStr)
 		if err != nil {
 			common.ErrorWithCode(c, 400, "Top must be an integer")
+			return
 		}
 	}
🤖 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/admin/enterprise_handler.go` around lines 1530 - 1536, In
ListUsersQuota, return immediately after common.ErrorWithCode reports an invalid
top parameter; add the missing return inside the strconv.Atoi error branch so
execution does not continue to the service call or success response.
🧹 Nitpick comments (1)
internal/admin/enterprise_handler.go (1)

543-543: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace remaining raw integer literals with typed ErrorCode constants for consistency.

Several functions in this file were partially migrated — CodeBadRequest/CodeNotFound/CodeUnauthorized calls now use typed constants, but 500/404/400 raw integers remain in the same functions. Since ErrorWithCode now accepts ErrorCode, replace these with common.CodeServerError, common.CodeNotFound, common.CodeBadRequest respectively to complete the migration.

♻️ Example fixes (apply similarly throughout the file)
-		common.ErrorWithCode(c, 500, err.Error())
+		common.ErrorWithCode(c, common.CodeServerError, err.Error())
-		common.ErrorWithCode(c, 404, "User not found")
+		common.ErrorWithCode(c, common.CodeNotFound, "User not found")
-		common.ErrorWithCode(c, 400, err.Error())
+		common.ErrorWithCode(c, common.CodeBadRequest, err.Error())

Also applies to: 599-599, 667-667, 735-735, 768-768, 808-808, 830-830, 833-833, 856-856, 860-860, 867-867, 870-870, 1305-1305, 1308-1308, 1336-1336, 1345-1345, 1353-1353, 1356-1356, 1516-1516, 1525-1525, 1534-1534, 1541-1541, 1544-1544, 1671-1671, 1674-1674, 1696-1696, 1700-1700, 1707-1707, 1710-1710, 1736-1736, 1739-1739

🤖 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/admin/enterprise_handler.go` at line 543, Replace every remaining
raw 500, 404, and 400 argument passed to ErrorWithCode throughout the affected
handlers with common.CodeServerError, common.CodeNotFound, and
common.CodeBadRequest respectively, including the calls near the listed
locations. Preserve each existing error message and ensure all ErrorWithCode
calls use typed ErrorCode constants consistently.
🤖 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.

Inline comments:
In `@internal/handler/providers.go`:
- Line 610: In AddModel, replace the success-path call to common.ErrorWithCode
with common.SuccessWithMessage, preserving the existing response code and
"success" message so the response includes the expected data field.

---

Outside diff comments:
In `@internal/admin/enterprise_handler.go`:
- Around line 1530-1536: In ListUsersQuota, return immediately after
common.ErrorWithCode reports an invalid top parameter; add the missing return
inside the strconv.Atoi error branch so execution does not continue to the
service call or success response.

---

Nitpick comments:
In `@internal/admin/enterprise_handler.go`:
- Line 543: Replace every remaining raw 500, 404, and 400 argument passed to
ErrorWithCode throughout the affected handlers with common.CodeServerError,
common.CodeNotFound, and common.CodeBadRequest respectively, including the calls
near the listed locations. Preserve each existing error message and ensure all
ErrorWithCode calls use typed ErrorCode constants consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b5778837-fd20-434f-ab54-aaa5c7c7e7f1

📥 Commits

Reviewing files that changed from the base of the PR and between eca8e87 and c4cd996.

📒 Files selected for processing (35)
  • cmd/ragflow_server.go
  • internal/admin/enterprise_handler.go
  • internal/admin/handler.go
  • internal/common/response.go
  • internal/handler/agent.go
  • internal/handler/agent_component.go
  • internal/handler/agent_test.go
  • internal/handler/agent_upload.go
  • internal/handler/agent_wait_for_user_test.go
  • internal/handler/bot.go
  • internal/handler/chat.go
  • internal/handler/chat_channel.go
  • internal/handler/chat_recommendation.go
  • internal/handler/chat_session.go
  • internal/handler/chunk.go
  • internal/handler/connector.go
  • internal/handler/dataset.go
  • internal/handler/document.go
  • internal/handler/file.go
  • internal/handler/file_commit.go
  • internal/handler/langfuse.go
  • internal/handler/llm.go
  • internal/handler/mcp.go
  • internal/handler/mcp_server.go
  • internal/handler/memory.go
  • internal/handler/plugin.go
  • internal/handler/providers.go
  • internal/handler/search.go
  • internal/handler/searchbot.go
  • internal/handler/skill_search.go
  • internal/handler/stats.go
  • internal/handler/system.go
  • internal/handler/tenant.go
  • internal/handler/user.go
  • internal/router/router.go

}

common.ErrorWithCode(c, int(code), "success")
common.ErrorWithCode(c, code, "success")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use SuccessWithMessage instead of ErrorWithCode for the success response in AddModel.

AddModel sends its success message through the error response helper, which omits the data field from the JSON envelope ({"code":0,"message":"success"}). Every other handler in this file uses SuccessWithMessage for no-data success responses, producing {"code":0,"data":null,"message":"success"}. This contract inconsistency can break clients that expect the data key.

🐛 Proposed fix
-	common.ErrorWithCode(c, code, "success")
+	common.SuccessWithMessage(c, "success")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
common.ErrorWithCode(c, code, "success")
common.SuccessWithMessage(c, "success")
🤖 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/providers.go` at line 610, In AddModel, replace the
success-path call to common.ErrorWithCode with common.SuccessWithMessage,
preserving the existing response code and "success" message so the response
includes the expected data field.

Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 10, 2026
Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN
JinHai-CN merged commit 0b01171 into infiniflow:main Jul 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant