Convert macro panics to compile errors - #21
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21 +/- ##
==========================================
+ Coverage 79.46% 80.74% +1.28%
==========================================
Files 9 9
Lines 448 561 +113
==========================================
+ Hits 356 453 +97
- Misses 92 108 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The RustEmbed derive macro previously called panic!() and .unwrap() on misconfiguration (non-unit struct, missing/duplicate folder, bad path interpolation, missing CARGO_MANIFEST_DIR, multiple prefixes). These produced opaque macro-expansion panics. Thread syn::Result through impl_rust_embed_for_web and emit syn::Error::new_spanned(...).to_compile_error() so users get proper compile-time diagnostics pointing at the derive instead of a panic. Ports upstream rust-embed commit 7a14d89. Claude-Session: https://claude.ai/code/session_01MixCkrYqoVEZZbPRRNtL3M
Apply rustfmt to the multi-argument generate_*_impl calls so the format check passes, and add unit tests that exercise impl_rust_embed_for_web directly: enum target, struct with fields, missing folder attribute, duplicate folder attributes, duplicate prefix attributes, and a valid unit struct. These cover the new syn::Error compile-error paths that the patch added. Claude-Session: https://claude.ai/code/session_01MixCkrYqoVEZZbPRRNtL3M
SeriousBug
force-pushed
the
move-panics-to-compile-errors
branch
from
June 30, 2026 01:09
3117c26 to
f3b8a75
Compare
The allow_missing change on master still panicked when the folder is missing and the opt-in is not set. Return a syn::Error like the other misconfiguration paths so it surfaces as a normal compile error. Add tests for both the missing-folder error and the allow_missing opt-in success path. Claude-Session: https://claude.ai/code/session_01MixCkrYqoVEZZbPRRNtL3M
Merged
SeriousBug
added a commit
that referenced
this pull request
Jun 30, 2026
* Bump version to 11.4.0 Releases changes since 11.3.0: - Add allow_missing derive attribute (#22) - Convert macro panics to compile errors (#21) - Use sorted const table + binary search for embedded get() (#24) - Update sha2 dependency to 0.11 (#25) * Pin time below 0.3.52 in dev-dependencies time 0.3.52 changed the Parsable::parse signature, which breaks cookie 0.16.2 (pulled in transitively via the actix-web dev-dependency), failing the CI doc test job. Constrain to the 0.3 series below 0.3.52 so it unifies with cookie's requirement.
SeriousBug
added a commit
that referenced
this pull request
Jul 1, 2026
impl/src/lib.rs uses syn::Error::new_spanned (added in #21), which needs the ToTokens trait from syn's "printing" feature. impl/Cargo.toml sets default-features = false without it, so the crate fails to compile when built in isolation — which is exactly what cargo publish's verification step does. The workspace test build passed only because feature unification pulled "printing" in via another crate. utils 11.4.0 already published before impl failed, so bump all crates to 11.4.1 to re-release cleanly.
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.
Ports the "Move Panics to Compile Errors" change from upstream rust-embed (commit 7a14d89).
What changed
The
RustEmbedderive macro previously calledpanic!()and.unwrap()when it hit a misconfiguration during macro expansion:folderattributeshellexpandinterpolation (interpolate-folder-pathfeature)CARGO_MANIFEST_DIRprefixattributeThese surfaced as opaque macro-expansion panics. Now
impl_rust_embed_for_webreturnssyn::Result<TokenStream2>and each error path emitssyn::Error::new_spanned(ast, msg). The publicderive(RustEmbed)entry converts a returnedErrintoe.to_compile_error(), so users get a normal compile error pointing at the derive.Valid inputs are unchanged: the generated code is identical, only the error paths differ.
Verification
cargo buildcargo testcargo test --all-featuresAll pass.
https://claude.ai/code/session_01MixCkrYqoVEZZbPRRNtL3M