fix(xerrors): keep outer fields when rendering collected errors - #449
Open
Kybxd wants to merge 1 commit into
Open
fix(xerrors): keep outer fields when rendering collected errors#449Kybxd wants to merge 1 commit into
Kybxd wants to merge 1 commit into
Conversation
Errors produced by a Collector lost the fields attached by enclosing WrapKV layers when rendered via Error(), so the default message template was used instead of the module-specific one (e.g. confgen). The book, sheet and cell position were therefore missing from confgen load errors, leaving no hint about which cell to fix: error[E2002]: field value not in referred space Reason: value "100033333" not in referred space "ItemConf.ID" Help: guarantee value "100033333" was configured in referred space "ItemConf.ID" ahead Two distinct causes are fixed: 1. collected did not implement fieldsRenderer, so base.renderWithFields fell back to the inner error's Error() and dropped all outer fields. 2. Collector.Collect only remembered the outermost withMessage layer of an already-collected error. Wrapper chains commonly spread fields across several layers (confgen adds Module in one layer and BookName/SheetName in another), so every layer down to the collected marker must be merged. This is what multi-importer sheets (merger or scatter) hit, since ParseMessage adds another wrapper layer that carries no Module. Both paths now render the module-specific template: error[E2002]: field value not in referred space Workbook: Activity_ActivityCenter.xlsx (Primary: Activity.xlsx) Worksheet: SectionConf DataCellPos: S218 DataCell: 100033333 Reason: value "100033333" not in referred space "ItemConf.ID" Help: guarantee value "100033333" was configured in referred space "ItemConf.ID" ahead
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #449 +/- ##
==========================================
+ Coverage 75.63% 75.65% +0.02%
==========================================
Files 88 88
Lines 9531 9543 +12
==========================================
+ Hits 7209 7220 +11
- Misses 1747 1748 +1
Partials 575 575 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
Errors produced by a
Collectorlose the fields attached by enclosingWrapKVlayers when rendered viaError(). SinceDesc.Stringifypicks the message template by theModulefield, losing it makes the default template render instead of the module-specific one.The practical impact:
confgenload errors loseWorkbook/Worksheet/DataCellPos/DataCell, so there is no hint about which cell to fix. A refer check failure looks like this:The fields are all correctly attached along the chain (
tableParser.ParseaddsCellDebugKV,parseMessageFromOneImporteraddsModule/BookName/SheetName) — they are only dropped at render time.This is easy to hit from a downstream checker built on
load, which reports issues viaerr.Error().Root causes
Two distinct bugs, each affecting a different sheet layout:
1.
collecteddid not implementfieldsRenderer.withMessage.Error()on a fields-only wrapper delegates throughbase.renderWithFields, which requires the cause to implementfieldsRenderer.collectedonly implementedError/Unwrap/Format, so rendering fell back toc.error.Error()— i.e.joinError.Error()==renderWithFields(nil)— discarding every outer field. This affects single-importer sheets.2.
Collector.Collectonly remembered the outermostwithMessagelayer.Wrapper chains commonly spread fields across several layers:
confgenaddsModuleinsheetParser.Parse's defer, thenBookName/SheetNameinparseMessageFromOneImporter, and for multiple importersParseMessage'sGroup.Goadds yet another layer carrying only book/sheet names and noModule. Keeping justerr.(*withMessage)therefore droppedModule, so multi-importer sheets (merger/scatter) still rendered the default template even after fix 1.Fix
fieldsRendereroncollected, forwardingouterFieldsto the inner error.outerFieldsUntil, which walks every wrapper layer between the error and thecollectedmarker and merges their fields (inner layers win), replacing the outermost-layer-only logic inCollect.Result
Both single- and multi-importer sheets now render the module-specific template:
For a
mergersheet it additionally pinpoints which merged workbook the bad cell lives in, which the primary book name alone cannot express.Tests
Two regression tests are added, mirroring the real
confgenchains (single-importer and multi-importer). Each was verified to fail independently when only its corresponding fix is reverted:TestCollected_ErrorPropagatesOuterFieldsfailsTestCollected_ReCollectPreservesAllWrapperFieldsfailsgo test ./...(includingtest/functest),go vetandgolangci-lint runall pass. Verified end to end against a real spreadsheet tree, where the reported cellSectionConf!S218was confirmed to hold the offending value.