Repository navigation
fix(sheet): store error cells produced by the error string converter - #1318
Sean-Walker0 wants to merge 2 commits into
Conversation
3d994b1 to
4c74f23
Compare
Mikkey-f
left a comment
There was a problem hiding this comment.
Thanks @Sean-Walker0 — the core fix is right, and it closes a real gap: StringErrorConverter is registered by default (DefaultConverterLoader, putAllConverter), but the executor rejected the ERROR type it produces, so the converter was read-only in practice.
Verification (Windows 11, JDK 17, 4c74f233)
- Green:
ErrorCellWriteTest2/2; fullfesod-common60 +fesod-sheet1,819 tests, 0 failures/errors;spotless:checkclean. - Red: with only
AbstractExcelWriteExecutor.javareverted,stringErrorConverterWritesAnErrorCellfails withExcelWriteDataConvertException: Not supported data:#DIV/0! return type:ERRORat row:1— the test pins the gap precisely. - Probes:
#N/Around-trips to a real ERROR cell in both XLSX and XLS (getCellType() == ERROR,ErrorEval.getText(...) == "#N/A"), so the fix is not XLSX-only.
One issue I think should be fixed before merge: CSV silently loses the value
AbstractExcelWriteExecutor is shared by the CSV writer (ExcelBuilderImpl → ExcelWriteAddExecutor with CsvWorkbook/CsvSheet). On the CSV path, CsvCell.setCellErrorValue(byte) stores the code in numberValue and leaves stringValue null, while CsvSheet.buildCellValue() does:
case STRING:
case ERROR:
return csvCell.getStringCellValue();So writing an ErrorModel to CSV produces the header row followed by an empty data cell (probe), i.e. the error text is silently dropped. Before this change the CSV write failed (here via the pre-existing #97 CsvWorkbook.hashCode/CsvSheet.hashCode recursion in the failure path), so the new behavior is silent loss rather than a supported write. Two minimal fixes:
- set
stringValue = ErrorEval.getText(value)inCsvCell.setCellErrorValue(byte), so the existing ERROR branch serializes the text, or - render
ErrorEval.getText(csvCell.getErrorCellValue())inCsvSheet.buildCellValue.
A CSV case in ErrorCellWriteTest would pin whichever you choose.
Non-blocking
- Invalid text (e.g.
"not-an-error") throws POI'sIllegalArgumentException: Unknown error code: not-an-error, without the row/column context the other write failures carry. Consider wrapping it inExcelWriteDataConvertException, or adding a test to document the failure mode. - The new test covers XLSX only; XLS works with the same code (probe above), so a parameterized XLS case would be cheap. CSV needs the handling above either way.
|
Thanks for the thorough verification and for catching the CSV gap — pushed as a follow-up commit (rebased onto current main):
|
0eb835a to
f65fc58
Compare
|
Follow-up also folded in (amended into the CSV commit, sorry for the squash): the non-blocking point is now addressed too — |
Mikkey-f
left a comment
There was a problem hiding this comment.
Thanks @Sean-Walker0 — both follow-ups check out on my side.
I re-verified on f65fc581:
CsvCell.setCellErrorValuenow keepsErrorEval.getText(value)next to the code, so the CSV ERROR branch writes#DIV/0!instead of an empty field. That is the first option from my earlier review, and the new CSV test pins it.- Wrapping
FormulaError.forString'sIllegalArgumentExceptioninExcelWriteDataConvertExceptiongives the failure the row context it was missing; the test asserts both the exception type and that the offending value is in the message.
Verification:
- Targeted
ErrorCellWriteTest: 5/5 (XLSX, XLS, CSV, unknown-value failure, plain-string regression). - Red side: reverting the two product files to
4c74f233reproduces exactly the two gaps — CSV expected"#DIV/0!"but was empty, and an unknown value threw POI'sIllegalArgumentExceptioninstead ofExcelWriteDataConvertException. - Full suite:
fesod-common60 +fesod-sheet1,822, 0 failures / 0 errors / 0 skipped; spotless passes; CI is 14/14 green.
One non-blocking nit: the new tests mix imports and fully qualified names (java.io.FileInputStream, java.util.List, org.apache.poi.ss.usermodel.Cell, etc.) even though the class already imports several of them — importing the rest would read a bit better. Not a blocker.
LGTM from my side.
StringErrorConverter is registered for both directions, and its write side produces an ERROR-typed WriteCellData - but the fillValue switch in the write executor had no ERROR case, so every write through the explicitly configured converter failed with 'Not supported data: ... return type:ERROR'. A registered converter whose output the executor cannot store is unusable by construction. Map the error text to its POI code with FormulaError.forString and store it via Cell.setCellErrorValue, symmetric with the read side that decodes error cells to the same '#NAME?' style text. Verified with ErrorCellWriteTest (the explicit-converter write throws before the change and produces a real error cell round-tripping '#DIV/0!' after; a plain string field write is pinned on both sides) plus the full fesod-sheet suite (1814 tests) and spotless:check.
CsvCell.setCellErrorValue stored only the numeric code, while CsvSheet.buildCellValue serializes ERROR cells through the string value - so writing through StringErrorConverter to CSV produced an empty field instead of the '#NAME?' style text. Keep the ErrorEval.getText rendering in stringValue alongside the code. Also pins the error-cell write on XLS (real ERROR cell round-trip) and CSV (error text line) in ErrorCellWriteTest.
f65fc58 to
2123bff
Compare
Purpose of the pull request
StringErrorConverteris registered for both directions (putAllConverter), and its write side produces an ERROR-typedWriteCellData— but thefillValueswitch in the write executor had no ERROR case, so every write through the explicitly configured converter failed:A registered converter whose output type the executor cannot store is unusable by construction:
@ExcelProperty(converter = StringErrorConverter.class)reads fine (the read side decodes error cells to#NAME?-style text) but can never write.No issue exists for this yet; found while auditing the converter/executor contract.
What's changed?
fillValuegains an ERROR case: the error text is mapped to its POI code viaFormulaError.forString(...)and stored throughCell.setCellErrorValue(byte)— the exact inverse of the read side, which surfaces error cells as the same#NAME?-style text (ErrorEval.getText, #1093). An unrecognized error text fails the conversion loudly, like any other conversion failure.Checklist
Verifying this change
ErrorCellWriteTest:stringErrorConverterWritesAnErrorCell— red before (Not supported data:#DIV/0! return type:ERROR), green after: the cell is a real POI error cell and#DIV/0!round-trips throughErrorEval.getText(getErrorCellValue());plainStringFieldStillWrites— pins ordinary string writes, green before and after../mvnw clean package -B -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheet: 1814 tests, 0 failures, 0 errors../mvnw -pl fesod-sheet spotless:check: clean.Notes
StringErrorConverter(and any custom converter returning an ERROR-typedWriteCellData) now produce error cells instead of throwing.fillPropertybelow this switch; perf(sheet): recycle CellWriteHandlerContext across cells of a write #1209/refactor: decouple read/write responsibilities and introduce ColumnBinding #1128/feat: Supports obtaining current row data object during writing #598 #619 touch other regions; feature: Support Dynamic Column in Fill Operation for Collection Data #455 is based on the pre-rename codebase and does not overlap this hunk.