Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove #[wasm_bindgen] errors with `compile_error!` #601
Comments
This comment has been minimized.
This comment has been minimized.
mkane0814
commented
Aug 1, 2018
|
Yes please! These errors have been really frustrating to work around. Does anyone know what causes them? |
alexcrichton
added a commit
to alexcrichton/wasm-bindgen
that referenced
this issue
Aug 1, 2018
alexcrichton
referenced this issue
Aug 1, 2018
Merged
Prepare to have targeted error diagnostics #604
This comment has been minimized.
This comment has been minimized.
|
@mkane0814 the errors here are an unfortunate artifact of how procedural macros work today with one of the primary vectors of generating errors being Put another way, "what causes the bad errors messages?" can be answered with "the entire macro today", which is bad! I've started to lay the groundwork for this in #604 |
alexcrichton
added a commit
to alexcrichton/wasm-bindgen
that referenced
this issue
Aug 1, 2018
alexcrichton
added a commit
to alexcrichton/wasm-bindgen
that referenced
this issue
Aug 1, 2018
alexcrichton
added a commit
that referenced
this issue
Aug 1, 2018
This comment has been minimized.
This comment has been minimized.
|
I think this is effectively done now, yay! |
alexcrichton
closed this
Aug 3, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alexcrichton commentedAug 1, 2018
Right now the procedural macro simply panics if anything goes wrong, but this is pretty bad! The error messages coming out look pretty opaque at times and are often quite subpar, especially in that they're pointing to the wrong items.
I've just realized, however, that the procedural macro can generate
compile_error!invocations which gives us the ability to generate custom compiler errors as well as custom error spans. An example of this is:https://gist.github.com/alexcrichton/35f9b54585b39d16a887cffd4eabdb2d
We should refactor the macro crate to use
Resultfor error handling and use a structured error type which has a string and start/end spans, and that way we can generate nicely spanned error messages, yay!