feat: return error cells as a typed CellError instead of null#42
Merged
Conversation
An error cell (#DIV/0!, #N/A, #REF!, ...) was collapsed to null, making it
indistinguishable from a blank cell — the error byte was read and thrown away in
decodeBoolErr and in a formula's cached error result. Both now decode it into a
new CellError value carrying the worksheet code, so importers can tell an errored
cell from an empty one, and from a text cell that literally contains "#N/A".
The BIFF error byte -> code mapping lives in its own small module; an unknown byte
falls back to null rather than guessing. CellError serializes to
{ "code": "#DIV/0!" } in JSON. Exports CellError and ExcelErrorCode, documented
in both READMEs.
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's wrong
When a cell holds an Excel error —
#DIV/0!,#N/A,#REF!,#VALUE!,#NAME?,#NUM!,#NULL!— the parser threw the error byte away and returnednull. That made an errored cell indistinguishable from a blank one, which matters for the exact thing this library is for: importing/validating spreadsheet data.The byte was right there —
decodeBoolErrread it and discarded it, and a formula's cached error result did the same.The change
Both paths now decode that byte into a typed value:
CellErroris distinct fromnull(blank) and from a text cell that literally contains"#N/A".{ "code": "#DIV/0!" }, so the CLI output marks errors explicitly too.nullrather than guessing (keeps the hardening posture).CellErrorclass andExcelErrorCodetype; both READMEs updated.Tests
errorFromByte: all seven defined codes, unknown-byte fallback,toString, and JSON shape.decodeBoolErr: booleans, error →CellError, unknown →null.decodeFormula: cached error result →CellError, cached blank →null.80 tests pass; typecheck, lint, build, prettier all clean.
Version
Behavior change (error cells were
null, nowCellError), so it's a minor bump →0.5.0. Callers who relied on error cells beingnullshould treat aCellErroras empty explicitly.