dillon1000/react

Commit

[rust] Start of error handling

Until now i've freely used `panic!`, `unwrap()`, and friends for "error 
handling". This PR switches to consistently returning `Result` within the HIR 
builder, using a structured error representation that exploits helpers from 
`thiserror` and `miette` crates. Miette has a super graphical formatter for 
diagnostics as you can see in the screenshot (also see the 
[repo](https://docs.rs/miette/5.9.0/miette/index.html)). 

This is just a first pass and we'll need to flush out the error handing story 
more. Two obvious directions to go next: 

* Make HIR construction error-tolerant, so that it can find as many errors as 
possible at once rather than failing on the first error. We did this in Relay 
Compiler as well, and we can likely borrow some of its helpers. 

* Decouple from `miette`. It's very nice but less flexible than I'd like. We can 
define our own more generic diagnostic type that contains structured data, then 
have a generic conversion mechanism into a miette type so we can use their 
display logic. 

<img width="789" alt="Screenshot 2023-07-06 at 3 55 38 PM" 
src="https://github.com/facebook/react-forget/assets/6425824/e1f1ed4b-5188-4af5-9af4-8f6c5c345023">
Browse files
Changed paths13 files
First-parent comparison
M compiler/forget/Cargo.lock ModifiedM compiler/forget/Cargo.toml ModifiedM compiler/forget/crates/build-hir/Cargo.toml ModifiedM compiler/forget/crates/build-hir/src/build.rs ModifiedM compiler/forget/crates/build-hir/src/builder.rs ModifiedA compiler/forget/crates/build-hir/src/error.rs AddedM compiler/forget/crates/build-hir/src/lib.rs ModifiedM compiler/forget/crates/estree/Cargo.toml ModifiedM compiler/forget/crates/estree/src/lib.rs ModifiedM compiler/forget/crates/fixtures/Cargo.toml ModifiedA compiler/forget/crates/fixtures/tests/fixtures/error.assign-to-global.js AddedM compiler/forget/crates/fixtures/tests/fixtures_test.rs ModifiedA compiler/forget/crates/fixtures/tests/snapshots/[email protected] Added
Patch

Files changed

Rendering syntax-highlighted changes…