Repository navigation
fix(import): refuse files too large to open, and let the file say empty from absent - #581
Merged
Merged
Conversation
…ty from absent Closes #366, #578. ## A file too large to show now says so (#366) read_file_contents read whatever it was given. Everything downstream — the Rust string, the JavaScript copy of it, the parsed rows — is held at once, so a multi-gigabyte CSV took the renderer down before the user saw anything. It now checks the size from the file's metadata and refuses before reading a byte, naming the size, the limit and what to do instead. The cap is 256 MB, chosen from what the pipeline survives rather than from disk. The issue asks for streaming, which is the right long-term answer and a much larger change: chunked reads, a chunked parse, and batched inserts driven by the chunks. Refusing is not that. It is the part that stops the app dying, and it is worth having whether or not streaming is built later. Applied in the command rather than the dialog, so restore gets it too — it reads whole files the same way. ## The file decides empty from absent (#578) Every empty cell became SQL NULL. CSV distinguishes `,,` from `,"",` but parseCSVLine discarded the quoting before anyone could act on it, so a NOT NULL column rejected a row the user considered valid and a nullable one silently stored NULL where the file said "". The parser now reports which cells were written bare, alongside the rows rather than changing their type, so every existing caller reads them unchanged. A bare empty becomes NULL and a quoted one stays "". A row shorter than its header is absent rather than empty, which is the same reading. generateBatchInsert takes the flags as an optional argument and behaves as it did without them. ## Two found while wiring it setCsvBareEmpty could be handed undefined by a caller predating the field, and the component then threw on .map when the import ran. Defaulted. The import callback used the new state without listing it as a dependency, so it would have closed over an empty array and treated every cell as absent — the same shape as the grid's memo in #555. Caught by lint, which is what that warning is for. Three Rust tests on the limit, four on the parser, three on the generator. Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Closes #366, #578.
A file too large to show now says so — #366
read_file_contentsread whatever it was given. Everything downstream — the Rust string, the JavaScript copy, the parsed rows — is held at once, so a multi-gigabyte CSV took the renderer down before the user saw anything.It now checks the size from the file's metadata and refuses before reading a byte, naming the size, the limit, and what to do instead. The cap is 256 MB, chosen from what the pipeline survives rather than from disk.
The issue asks for streaming. That's the right long-term answer and a much larger change — chunked reads, a chunked parse, batched inserts driven by the chunks. This isn't that. It's the part that stops the app dying, and it's worth having whether or not streaming is built later.
Applied in the command rather than the dialog, so restore gets it too — it reads whole files the same way.
The file decides empty from absent — #578
Every empty cell became SQL
NULL. CSV distinguishes,,from,"",, butparseCSVLinediscarded the quoting before anyone could act on it — so aNOT NULLcolumn rejected a row the user considered valid, and a nullable one silently stored NULL where the file said"".The parser now reports which cells were written bare, alongside the rows rather than changing their type, so every existing caller reads them unchanged. A bare empty becomes NULL; a quoted one stays
"". A row shorter than its header is absent rather than empty, which is the same reading.generateBatchInserttakes the flags as an optional argument and behaves exactly as before without them.Two bugs found while wiring it up
setCsvBareEmptycould be handedundefinedby a caller predating the field, and the component then threw on.mapwhen the import ran. Defaulted.The import callback used the new state without listing it as a dependency — it would have closed over an empty array and treated every cell as absent. Same shape as the grid's memo in #555. Caught by the lint warning, which is what that rule is for.
Tests
Three Rust on the limit (over it refuses and names both sizes, at it succeeds, and the byte formatting), four on the parser, three on the generator.
1796 unit + 299 browser, 18 Rust lib; clippy/tsc/dprint/eslint clean.
🤖 Generated with Claude Code