Skip to content

refactor(xerrors): structured desc rendering and format improvements#387

Open
wenchy wants to merge 16 commits intomasterfrom
refactor/xerrors-structured-desc-and-format
Open

refactor(xerrors): structured desc rendering and format improvements#387
wenchy wants to merge 16 commits intomasterfrom
refactor/xerrors-structured-desc-and-format

Conversation

@wenchy
Copy link
Copy Markdown
Member

@wenchy wenchy commented Apr 11, 2026

Summary

Refactors the xerrors package into internal/x/xerrors with a new structured error collection system supporting multi-level hierarchies.

Key Changes

New: Hierarchical Error Collector (internal/x/xerrors/collector.go)

  • Collector accumulates errors concurrently up to a configurable limit
  • Supports parent-child hierarchy: global → book → sheet → message
  • NewChild() / Join() for tree-based error aggregation
  • Group ties errgroup.Group to a Collector for concurrent collection

Refactored: xerrorsinternal/x/xerrors

  • Moved and restructured desc.go, errors.go, stack.go into internal/x/xerrors
  • Replaced containsMultiError + NewDesc trick with fieldsRenderer interface
  • Simplified Collector API, cleaned up comments and lint warnings
  • Removed old xerrors/ top-level package

Integration Tests

  • Added confgen collector integration tests with CSV testdata (normal + overflow cases, multi-workbook)
  • Added protogen collector integration tests with CSV testdata (normal + overflow cases, multi-workbook)
  • Fixed non-deterministic test output ordering across OS

Documentation

  • Added internal/confgen/README.md: parsing hierarchy and error collector hierarchy (with Mermaid diagrams)
  • Added internal/protogen/README.md: parsing hierarchy and error collector hierarchy (with Mermaid diagrams)

- Add NewDesc(err) to extract structured fields from error chain
- Add fieldsCarrier interface for structured key-value field access
- Add withMessage.replacesCause to allow message to fully replace cause text
- Format %+v now renders NewDesc(err).String() + stack trace
- Format Error()/%v/%s only renders the plain reason/error text
- Remove unused cause parameter from format() function signature
- Improve test coverage: add meaningful %+v test cases with ecode errors
  showing real difference from %s/%v (structured desc vs plain text)
- assertError now verifies %+v starts with NewDesc(err).String()
- func_test.go: use require.NoErrorf with NewDesc for rich error output
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

❌ Patch coverage is 76.36196% with 256 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.28%. Comparing base (5a4e7fc) to head (43aa3c1).

Files with missing lines Patch % Lines
internal/confgen/table_parser.go 77.16% 54 Missing and 46 partials ⚠️
internal/x/xerrors/errors.go 72.51% 39 Missing and 8 partials ⚠️
internal/confgen/confgen.go 73.71% 29 Missing and 17 partials ⚠️
internal/protogen/protogen.go 58.97% 15 Missing and 1 partial ⚠️
internal/x/xerrors/desc.go 85.32% 10 Missing and 6 partials ⚠️
internal/confgen/parser.go 67.64% 9 Missing and 2 partials ⚠️
internal/x/xerrors/collector.go 90.52% 7 Missing and 2 partials ⚠️
cmd/tableauc/main.go 0.00% 4 Missing ⚠️
internal/confgen/document_parser.go 81.81% 1 Missing and 1 partial ⚠️
internal/protogen/document_parser.go 0.00% 1 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #387      +/-   ##
==========================================
+ Coverage   74.05%   74.28%   +0.22%     
==========================================
  Files          87       88       +1     
  Lines        8819     9100     +281     
==========================================
+ Hits         6531     6760     +229     
- Misses       1718     1768      +50     
- Partials      570      572       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}
}

// ScatterAndExport
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate notes

sheetBeginTime := time.Now()
if specifiedSheetName != "" {
if specifiedSheetName != sheetName {
continue sheetLoop
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

// NOTE: the global options has been merged into book options on protogen,
// so there is no need to set it here.
header := tableparser.NewHeader(p.sheetOpts, p.bookOpts, nil)
err := tableparser.RangeDataRows(table, header, func(r *book.Row) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tableparser.RangeDataRows fails fast when error occurs, so maybe we should change its iterating logic to adapt to the error collector?

@Kybxd
Copy link
Copy Markdown
Collaborator

Kybxd commented Apr 15, 2026

Since error collector is passed as function params, should there functions still return an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants