Skip to content

refactor(data): establish common UnfoldError for shared errors#967

Open
thomasathorne wants to merge 1 commit intomainfrom
thomasa/common-unfold-errors
Open

refactor(data): establish common UnfoldError for shared errors#967
thomasathorne wants to merge 1 commit intomainfrom
thomasa/common-unfold-errors

Conversation

@thomasathorne
Copy link
Copy Markdown
Contributor

@thomasathorne thomasathorne commented Mar 30, 2026

Relates to TZX-106.

What

Switch the associated type Error in the Unfold trait with a specific error type UnfoldError (that includes two 'custom' error variants, one for component-specific errors and one for source-specific errors).

Why

In working on the BlobStoreUnfold I realised that most of the errors will be common ones that apply to almost any Unfold implementation---basically, incorrect tree shapes. We can save a lot of code duplication by putting these in a common type.

Manually Testing

make all

Tasks for the Author

  • Link all Linear issues related to this MR using magic words (e.g. part of, relates to, closes).
  • Eliminate dead code and other spurious artefacts introduced in your changes.
  • Document new public functions, methods and types.
  • Make sure the documentation for updated functions, methods, and types is correct.
  • Add tests for bugs that have been fixed.
  • Explain changes to regression test captures when applicable.
  • Write commit messages in agreement with our guidelines.
  • Self-review your changes to ensure they are high-quality.
  • Complete all of the above before assigning this MR to reviewers.

@thomasathorne thomasathorne force-pushed the thomasa/common-unfold-errors branch from 6e282e0 to fa21d32 Compare March 30, 2026 09:43
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.68%. Comparing base (ab5bf0d) to head (fa21d32).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pvm/src/machine_state.rs 0.00% 2 Missing ⚠️
pvm/src/machine_state/registers.rs 0.00% 2 Missing ⚠️
data/src/foldable.rs 50.00% 1 Missing ⚠️
pvm/src/machine_state/csregisters.rs 0.00% 1 Missing ⚠️
pvm/src/machine_state/hart_state.rs 0.00% 1 Missing ⚠️
pvm/src/machine_state/memory/buddy/branch.rs 0.00% 1 Missing ⚠️
.../machine_state/memory/buddy/branch_combinations.rs 0.00% 1 Missing ⚠️
pvm/src/machine_state/memory/buddy/leaf.rs 0.00% 1 Missing ⚠️
pvm/src/machine_state/memory/state.rs 0.00% 1 Missing ⚠️
pvm/src/machine_state/reservation_set.rs 0.00% 1 Missing ⚠️
... and 4 more

❌ Your patch check has failed because the patch coverage (42.85%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #967      +/-   ##
==========================================
- Coverage   89.78%   89.68%   -0.11%     
==========================================
  Files         110      110              
  Lines       22104    22138      +34     
  Branches    22104    22138      +34     
==========================================
+ Hits        19846    19854       +8     
- Misses       1859     1889      +30     
+ Partials      399      395       -4     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

Benchmark results for revision 520df2c:

Metric Duration TPS
Mean 1.516204434s 26.382
Worst 1.52752262s 26.186
Best 1.5087486s 26.512
Standard Deviation ±4.57824ms ±0.080
Full results
Run Transfers Duration TPS
1 40 1.519772932s 26.320
2 40 1.519900551s 26.318
3 40 1.521205127s 26.295
4 40 1.515488073s 26.394
5 40 1.509618215s 26.497
6 40 1.52752262s 26.186
7 40 1.513787424s 26.424
8 40 1.521535787s 26.289
9 40 1.513756351s 26.424
10 40 1.517734681s 26.355
11 40 1.5087486s 26.512
12 40 1.514049966s 26.419
13 40 1.510585693s 26.480
14 40 1.511100068s 26.471
15 40 1.513776659s 26.424
16 40 1.520781065s 26.302
17 40 1.513982873s 26.420
18 40 1.518038149s 26.350
19 40 1.516646426s 26.374
20 40 1.51605742s 26.384

Compare the results above with those for the default branch.

Comment on lines +199 to +202
OfComponent(Box<dyn std::error::Error>),

#[error("Source specific error: {0}")]
OfSource(Box<dyn std::error::Error>),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

more curious about your opinion here and learning - claude pointed out that these variants will not support Send and Sync, because dyn Error doesn't, and this prevents compatibility with anyhow::Error or std::io::Error. I think this is only relevant in threaded/async contexts, which wouldn't be the case for Unfold uses?

Copy link
Copy Markdown
Contributor Author

@thomasathorne thomasathorne Mar 30, 2026

Choose a reason for hiding this comment

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

I think Claude is misleading you here, if you need Send or Sync you can add those traits to the dyn: eg.

OfSource(Box<dyn std::error::Error + Send + Sync>)

and then as long as you make sure the other error types you want to use do indeed implement those traits you are fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry wasn't clear - the edit you suggested is the same that it suggested. I was more curious about the effects of it - i.e. do we care about those compatibility requirements now or in the future. I imagine not because we won't need Unfold in async contexts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, it's an interesting question, I could imagine there might be a thread running in the rollup node that checks out snapshots (which will mean unfolding them from storage) before processing them in some way, for example while playing refutation games. If the unfold returns an error the thread might handle it all locally in which case there's no need for Send, but it's also conceivable we'd want to pass the error to a logging thread to be reported on. 🤔

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.

3 participants