Repository navigation
Go: fix warnings - #17738
Go: fix warnings#17738
Conversation
Signed-off-by: Jin Hai <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR standardizes error messages, supports wrapped-error matching with ChangesConsistency and maintenance
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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.
Actionable comments posted: 7
🤖 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/agent/runtime/helpers_test.go`:
- Around line 133-137: Update the error-path assertion around TrackProgress to
enforce the intended pass-through contract: compare got and want by exact
identity rather than using errors.Is, and retain failure wording that explicitly
reports identity mismatches. Only allow wrapping if the surrounding contract is
intentionally changed, in which case rename the test and revise nearby wording
accordingly.
In `@internal/agent/runtime/helpers.go`:
- Line 17: Update the package comment above the runtime package declaration to
remove the legacy Python migration reference and describe the current Go package
as providing cross-cutting runtime helpers.
In `@internal/deepdoc/parser/pdf/tool/compare.go`:
- Line 331: Update the exported-function comment for CompareTablesWithPython to
use a complete sentence with a verb, stating that it compares tables with Python
and includes per-cell text comparison.
In `@internal/handler/chat_session.go`:
- Around line 108-110: Update the authorization check in the chat session
handler to match the lowercase normalized error text returned by the service, so
ownership failures containing “no authorization” receive CodeAuthenticationError
(109) instead of the generic 500 response. Preserve the existing response
behavior and strings.Contains flow.
In `@internal/handler/document.go`:
- Line 639: Update the error message returned by the document option validation
near the conflicting docID/docIDs check to include a colon between the "'ids'"
label and the docIDs value, matching the "'ids':..." format used by the dataset
CRUD validation.
In `@internal/harness/graph/errors/errors_test.go`:
- Line 5: Update the nil-input assertions in the ChainError tests to use direct
pointer identity checks, verifying that the returned error is exactly the
original newErr or baseErr instance. Preserve the existing cases and avoid
value-based error comparisons for these paths.
In `@internal/ingestion/component/file.go`:
- Line 17: Update the package comment in file.go to remove the “Phase 2.1” and
Python-port migration references, and replace the File-only wording with a
concise current description covering the ingestion components in the package.
🪄 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 Plus
Run ID: e5da9e78-0972-43e4-aeeb-6de43166ba1e
📒 Files selected for processing (85)
internal/agent/component/begin.gointernal/agent/runtime/helpers.gointernal/agent/runtime/helpers_test.gointernal/agent/tool/code_exec_contract.gointernal/agent/tool/exesql_trino_stub.gointernal/agent/tool/retrieval_nlp_test.gointernal/agent/tool/searxng.gointernal/common/format.gointernal/deepdoc/client_test.gointernal/deepdoc/parser/pdf/layout/boxes_sections.gointernal/deepdoc/parser/pdf/layout/chars_boxes.gointernal/deepdoc/parser/pdf/tool/compare.gointernal/deepdoc/parser/pdf/util/crop.gointernal/deepdoc/parser/pdf/util/geometry.gointernal/engine/elasticsearch/chunk_helpers_test.gointernal/engine/elasticsearch/client.gointernal/engine/infinity/chunk.gointernal/engine/infinity/client.gointernal/engine/redis/redis.gointernal/entity/chat.gointernal/entity/models/302ai.gointernal/entity/models/aliyun.gointernal/entity/models/anthropic.gointernal/entity/models/astraflow.gointernal/entity/models/azure_openai.gointernal/entity/models/baichuan.gointernal/entity/models/baidu.gointernal/entity/models/builtin.gointernal/entity/models/cohere.gointernal/entity/models/huaweicloud.gointernal/handler/agent.gointernal/handler/agent_component.gointernal/handler/agent_upload.gointernal/handler/agent_webhook_security.gointernal/handler/agent_webhook_test.gointernal/handler/bot_test.gointernal/handler/chat_session.gointernal/handler/dataset_artifact.gointernal/handler/document.gointernal/handler/openai_chat.gointernal/handler/search.gointernal/harness/core/event_sender.gointernal/harness/core/retry_test.gointernal/harness/graph/checkpoint/nats.gointernal/harness/graph/errors/errors_test.gointernal/harness/graph/managed/managed.gointernal/harness/graph/pregel/pregel_durability_timetravel_test.gointernal/harness/graph/pregel/pregel_fault_edge_test.gointernal/harness/graph/pregel/pregel_fault_injection_test.gointernal/harness/graph/pregel/pregel_pressure_test.gointernal/harness/graph/task/decorator_test.gointernal/ingestion/component/chunker/group.gointernal/ingestion/component/dispatch_model.gointernal/ingestion/component/file.gointernal/ingestion/component/parser.gointernal/ingestion/component/parser_check_test.gointernal/ingestion/component/parser_dispatch.gointernal/ingestion/component/tokenizer.gointernal/ingestion/pipeline/pipeline.gointernal/ingestion/task/chunk_utils_test.gointernal/ingestion/task/pipeline_real_integration_test.gointernal/parser/chunk/execute.gointernal/service/agent_dbcheck.gointernal/service/agent_test.gointernal/service/bot.gointernal/service/chat_pipeline_test.gointernal/service/chat_session.gointernal/service/chat_session_contract_test.gointernal/service/chat_session_test.gointernal/service/chunk/chunk.gointernal/service/compilation_template_service.gointernal/service/dataset/crud.gointernal/service/dataset/list_test.gointernal/service/dataset_artifact_service.gointernal/service/deep_researcher.gointernal/service/document/document.gointernal/service/document/document_crud.gointernal/service/document/document_dataset_update.gointernal/service/document/document_metadata.gointernal/service/document/document_test.gointernal/service/file/file_upload.gointernal/service/model_chat.gointernal/service/nlp/retrieval.gointernal/service/pipeline_params.gointernal/service/pipeline_params_test.go
💤 Files with no reviewable changes (1)
- internal/service/dataset_artifact_service.go
| // err path — exact identity preserved | ||
| want := errors.New("exact") | ||
| got := TrackProgress("Foo", rec.callback, func() error { return want }) | ||
| if got != want { | ||
| if !errors.Is(got, want) { | ||
| t.Fatalf("err not propagated by identity: got %v (%T), want %v (%T)", got, got, want, want) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve the pass-through contract or update the test contract.
errors.Is(got, want) accepts a new wrapped error, but this test and its failure text still require exact identity. A regression that wraps want would now pass. Keep got != want if exact identity is required; otherwise rename the test and update the nearby wording to state that wrapping is allowed.
🤖 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/agent/runtime/helpers_test.go` around lines 133 - 137, Update the
error-path assertion around TrackProgress to enforce the intended pass-through
contract: compare got and want by exact identity rather than using errors.Is,
and retain failure wording that explicitly reports identity mismatches. Only
allow wrapping if the surrounding contract is intentionally changed, in which
case rename the test and revise nearby wording accordingly.
| // | ||
|
|
||
| // Cross-cutting helpers that replace Python's `rag/flow/base.py:ProcessBase` | ||
| // Package runtime implements Cross-cutting helpers that replace Python's `rag/flow/base.py:ProcessBase` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the migration-history reference from this package comment.
rag/flow/base.py:ProcessBase identifies the legacy Python implementation. This comment must describe the current Go package. Use a current-runtime description, such as Package runtime provides cross-cutting runtime helpers.
As per coding guidelines, **/*.go package and doc comments must align with the current runtime path rather than migration history.
🤖 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/agent/runtime/helpers.go` at line 17, Update the package comment
above the runtime package declaration to remove the legacy Python migration
reference and describe the current Go package as providing cross-cutting runtime
helpers.
Source: Coding guidelines
| } | ||
|
|
||
| // including per-cell text comparison. | ||
| // CompareTablesWithPython including per-cell text comparison. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Complete the exported-function comment.
The comment starts with CompareTablesWithPython, but it has no verb. Replace it with:
// CompareTablesWithPython compares tables with Python, including per-cell text comparison.
🤖 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/deepdoc/parser/pdf/tool/compare.go` at line 331, Update the
exported-function comment for CompareTablesWithPython to use a complete sentence
with a verb, stating that it compares tables with Python and includes per-cell
text comparison.
| docIDs := queryValues(c, "ids") | ||
| if docID != "" && len(docIDs) > 0 { | ||
| return opts, fmt.Sprintf("Should not provide both 'id':%s and 'ids'%v", docID, docIDs) | ||
| return opts, fmt.Sprintf("should not provide both 'id':%s and 'ids'%v", docID, docIDs) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add the missing separator before the ids value.
Line 639 renders "'ids'[...]". Use the same "'ids':..." format as internal/service/dataset/crud.go.
Proposed fix
- return opts, fmt.Sprintf("should not provide both 'id':%s and 'ids'%v", docID, docIDs)
+ return opts, fmt.Sprintf("should not provide both 'id':%s and 'ids':%v", docID, docIDs)📝 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.
| return opts, fmt.Sprintf("should not provide both 'id':%s and 'ids'%v", docID, docIDs) | |
| return opts, fmt.Sprintf("should not provide both 'id':%s and 'ids':%v", docID, docIDs) |
🤖 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` at line 639, Update the error message returned
by the document option validation near the conflicting docID/docIDs check to
include a colon between the "'ids'" label and the docIDs value, matching the
"'ids':..." format used by the dataset CRUD validation.
| package errors | ||
|
|
||
| import ( | ||
| "errors" |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -A12 -B2 'func ChainError\(base error, newErr error\)' internal/harness/graph/errors/errors.goRepository: infiniflow/ragflow
Length of output: 527
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect the relevant test section around ChainError tests.
rg -n -A40 -B10 'errors\.Is\(nilChained|errors\.Is\(nilChained2|errors\.Is\(chained' internal/harness/graph/errors/errors_test.go || true
# Inspect full test file length and focused lines if present.
wc -l internal/harness/graph/errors/errors_test.go
sed -n '180,225p' internal/harness/graph/errors/errors_test.goRepository: infiniflow/ragflow
Length of output: 2936
🌐 Web query:
Go errors.Is nil target documented behavior nil target returns false if err is nil or wraps nil target
💡 Result:
The behavior of errors.Is(err, nil) is that it returns true if and only if err is nil [1][2]. Specifically, the Go standard library implements errors.Is such that if the target argument is nil, it performs a simple equality check: return err == target [1][2]. This behavior is well-established in the source code [1][2], though it is not explicitly documented as a feature in the official errors package documentation [3][4]. Because errors.Is(err, nil) is functionally equivalent to err == nil, the Go team and community generally maintain that the standard idiomatic way to check for a nil error remains err != nil [3][5]. Proposals to change this behavior—such as allowing errors.Is(err, nil) to return true for typed nil pointers or other "empty" error states—have been rejected to avoid complexity and maintain consistency with existing Go idioms [5][6][7].
Citations:
- 1: https://go.dev/src/errors/wrap.go?m=text
- 2: https://github.com/golang/go/blob/0fd7be7ee5f36215b5d6b8f23f35d60bf749805a/src/errors/wrap.go
- 3: proposal: errors: document what errors.Is(x, nil) means golang/go#73122
- 4: https://pkg.go.dev/errors
- 5: errors: Is(nil) behaves unexpectedly golang/go#40442
- 6: proposal: errors: allow implementing err.Is(nil) == true golang/go#40673
- 7: proposal: errors: Is resolve nil error problem golang/go#40674
Preserve identity checks for nil-input paths.
ChainError returns newErr or baseErr directly when the other argument is nil. Replace these assertions with direct pointer checks so the test still enforces that ChainError preserves the input error in nil-input paths.
🤖 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/harness/graph/errors/errors_test.go` at line 5, Update the nil-input
assertions in the ChainError tests to use direct pointer identity checks,
verifying that the returned error is exactly the original newErr or baseErr
instance. Preserve the existing cases and avoid value-based error comparisons
for these paths.
| // | ||
|
|
||
| // File ingestion component (Phase 2.1) — port of python `rag/flow/file.py`. | ||
| // Package component implements File ingestion component (Phase 2.1) — port of python `rag/flow/file.py`. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove migration history from the package comment.
Line 17 includes Phase 2.1 and port of python, which describe migration history rather than the current runtime path. The comment also describes only the File component although the package contains multiple ingestion components.
Use a current package-level description.
As per coding guidelines, keep package and doc comments aligned with the current runtime path rather than migration history.
Proposed fix
-// Package component implements File ingestion component (Phase 2.1) — port of python `rag/flow/file.py`.
+// Package component implements the ingestion workflow components.📝 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.
| // Package component implements File ingestion component (Phase 2.1) — port of python `rag/flow/file.py`. | |
| // Package component implements the ingestion workflow components. |
🤖 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/ingestion/component/file.go` at line 17, Update the package comment
in file.go to remove the “Phase 2.1” and Python-port migration references, and
replace the File-only wording with a concise current description covering the
ingestion components in the package.
Source: Coding guidelines
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
api/utils/validation_utils.py (1)
1106-1106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep immutable-field error messages consistent.
validate_immutable_fieldsnow returns lowercase, punctuation-free text forchunk_count. The adjacenttoken_countandprogressbranches still return title-case messages with periods. If this API error contract is being normalized, update all three branches and their tests in the same change. Otherwise, confirm thatchunk_countis intentionally different.🤖 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 `@api/utils/validation_utils.py` at line 1106, Normalize immutable-field validation error messages consistently across the chunk_count, token_count, and progress branches in validate_immutable_fields, and update their tests to match the chosen message format. If chunk_count is intentionally different, preserve it and document or verify that contract instead of changing the adjacent branches.
🤖 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 `@cmd/ragflow_server.go`:
- Around line 246-253: Recompute logFileName after the mode-specific logic has
finalized serverName, before constructing the final FileOutput. Update the flow
around serverName assignment and the later default api/admin port handling so
FileOutput receives a filename derived from the final server name rather than
the earlier value.
In `@docs/references/http_api_reference.md`:
- Line 7523: Align the documented response for GET /api/v1/files/{file_id} with
the behavior in the file-download handler: update the example’s application code
to match common.CodeUnauthorized returned when GetFileContent fails, or revise
the handler if 404 is the intended API contract. Keep the documentation and
handler consistent.
In `@internal/common/logger.go`:
- Line 51: Update InitLogger so file output is not silently skipped when
FileOutput.Path is empty: preserve the configured lumberjack sink by populating
Filename for every FileOutput caller, including the configurations in
cmd/ragflow_server.go, and add an appropriate fallback for an empty Path. Keep
the documented file-output behavior consistent across all callers.
---
Nitpick comments:
In `@api/utils/validation_utils.py`:
- Line 1106: Normalize immutable-field validation error messages consistently
across the chunk_count, token_count, and progress branches in
validate_immutable_fields, and update their tests to match the chosen message
format. If chunk_count is intentionally different, preserve it and document or
verify that contract instead of changing the adjacent branches.
🪄 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 Plus
Run ID: f564b9df-a52c-49d2-8d46-1646c6111a4b
📒 Files selected for processing (18)
api/apps/restful_apis/agent_api.pyapi/apps/restful_apis/chunk_api.pyapi/apps/restful_apis/document_api.pyapi/apps/services/document_api_service.pyapi/apps/services/file_api_service.pyapi/db/services/file_service.pyapi/utils/validation_utils.pycmd/ragflow_server.godocs/references/http_api_reference.mdinternal/common/logger.gointernal/handler/document.gointernal/service/file/file_content.gotest/testcases/restful_api/test_document_raw_routes.pytest/testcases/restful_api/test_documents.pytest/testcases/test_http_api/test_file_management_within_dataset/test_update_document.pytest/testcases/test_web_api/test_document_app/test_document_metadata.pytest/unit_test/api/apps/restful_apis/test_attachment_download_missing_blob.pytest/unit_test/api/utils/test_doc_validation.py
| { | ||
| "code": 404, | ||
| "message": "Document not found!" | ||
| "message": "document not found" |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Align the file-download response code with the handler.
Line 7523 documents application code: 404 for GET /api/v1/files/{file_id}. The supplied internal/handler/file.go, Lines 456-469, returns common.CodeUnauthorized when GetFileContent fails. Update the example to match the handler, or change the handler if 404 is the intended contract.
This finding is based on the supplied downstream handler context.
🤖 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 `@docs/references/http_api_reference.md` at line 7523, Align the documented
response for GET /api/v1/files/{file_id} with the behavior in the file-download
handler: update the example’s application code to match common.CodeUnauthorized
returned when GetFileContent fails, or revise the handler if 404 is the intended
API contract. Keep the documentation and handler consistent.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17738 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
No description provided.