fix(parser): return real error from csvIterator.NextRow instead of nil#2719
Open
nankingjing wants to merge 1 commit into
Open
fix(parser): return real error from csvIterator.NextRow instead of nil#2719nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
NextRow read the row error into a local variable e, but on the non-EOF error path it returned the named return value err (never assigned, so always nil). parseByRowIterator treats a nil error as success, so genuine CSV parse failures were silently swallowed and the failing row dropped. Return e so the real error propagates.
Author
Review: fix-csv-nextrow-swallow-err (#2719)Verdict: LGTM Classic Go named-return-value bug. The function signature is The fix changes the return to No issues found. Merge-ready. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
csvIterator.NextRowreturns a nil error on genuine (non-EOF) CSV read failures, so parse errors are silently swallowed.backend/infra/document/parser/impl/builtin/parse_csv.go:The actual read error is captured in the local variable
e. The namedreturn
erris never assigned anywhere in the function, so it is alwaysnil. On the non-EOF error path the function therefore returns(nil, false, nil)instead of surfacinge.Why it matters
The caller
parseByRowIterator(parse_iter.go) relies on this error toabort parsing:
Because
errisnil, a malformed CSV row (e.g. a quoting error or aErrFieldCountmismatch surfaced byencoding/csv) is not reported.The loop treats the failed read as an empty row, drops it, and continues
— so CSV parsing silently loses data instead of failing loudly. EOF is
handled separately and correctly (
return nil, true, nil); only the realerror path is broken.
Fix
Return the actual error
eon the non-EOF path:One-line, focused change. The EOF and success paths are unchanged.
Verification
Verified by reading; not executed (no Go toolchain available in this
environment). The change is a direct language-semantics fix: the local
eholds the real error fromcsv.Reader.Read(), while the named returnerris provably nil at that point.