Add basic error handling for invalid paths in proc_macro attribute
Dependencies
- [2]
NO3PDO7PRefactor `fluent_embed` to support structs - [3]
56F2YE6HUse `prettyplease` to format macro output - [4]
VZYZRAO4Move `output-macros` crate into workspace - [5]
5FIVUZYFUnify `fluent_embed` macro API as `localize()` - [6]
VNSHGQYNSupport using glob paths in `localize` macro - [7]
UKFEFT6LCreate basic `Output` proc-macro - [8]
O77KA6C4Create `fluent_embed` crate - [9]
WBI5HFOBAdd simple wrapper for `libc::settext()` to query system locale - [10]
SHNZZSZGCreate `cli_macros` shim crate - [11]
5TEX4MNUSplit `fluent_embed` into `group` and `parse` modules - [12]
D652S2N3Rename `parse` module to `parse_fluent` - [13]
XGNME3WRMove `Group::derive_enum` to new `crate::parse_macro` module - [14]
UOMQT7LTAdd support for cardinal CLDR plural selectors
Change contents
- replacement in fluent_embed/src/lib.rs at line 13
pub fn attribute_groups(path_literal: &syn::LitStr) -> Group {pub fn attribute_groups(path_literal: &syn::LitStr) -> Result<Group, wax::GlobError> { - replacement in fluent_embed/src/lib.rs at line 20
let glob = wax::Glob::new(&attribute_glob).unwrap();let glob = wax::Glob::new(&attribute_glob)?; - replacement in fluent_embed/src/lib.rs at line 23
let entry = potential_entry.unwrap();let entry = potential_entry?; - replacement in fluent_embed/src/lib.rs at line 36
Group::new(locale!("en-US"), resources)Ok(Group::new(locale!("en-US"), resources)) - replacement in fluent_embed/src/lib.rs at line 39
pub fn localize(path: &syn::LitStr, derive_input: &DeriveInput) -> TokenStream {let group = attribute_groups(path);pub fn localize(path: &syn::LitStr,derive_input: &DeriveInput,) -> Result<TokenStream, wax::GlobError> {let group = attribute_groups(path)?; - replacement in fluent_embed/src/lib.rs at line 52
quote! {Ok(quote! { - replacement in fluent_embed/src/lib.rs at line 59
}}) - edit in cli_macros/src/lib.rs at line 4
use proc_macro_error::{emit_error, proc_macro_error}; - replacement in cli_macros/src/lib.rs at line 6
use syn::{parse_macro_input, DeriveInput};use syn::parse_macro_input;use wax::GlobError; - edit in cli_macros/src/lib.rs at line 10
#[proc_macro_error] - replacement in cli_macros/src/lib.rs at line 13
let parsed_attribute: syn::LitStr = parse_macro_input!(attribute);let parsed_input = parse_macro_input!(item as DeriveInput);let derive_attribute: syn::LitStr = parse_macro_input!(attribute);let derive_input = parse_macro_input!(item); - replacement in cli_macros/src/lib.rs at line 16
let implementation = fluent_embed::localize(&parsed_attribute, &parsed_input);let implementation = match fluent_embed::localize(&derive_attribute, &derive_input) {Ok(implementation) => implementation,Err(glob_error) => {// Emit the relevant error messagesmatch glob_error {GlobError::Build(_build_error) => todo!(),GlobError::Walk(walk_error) => {// Generate help textlet help = if let Some(path) = walk_error.path() {let path_name = path.to_str().unwrap();// Might hit an error if file exists but insufficient permissionsmatch path.try_exists() {Ok(true) => {format!("the path `{path_name}` exists, but unable to access it")}_ => format!("the path `{path_name}` doesn't seem to exist"),}} else {String::from("no associated path")};emit_error! { derive_attribute, "error at depth {} while walking path", walk_error.depth();help = help;}}};// Generate a minimal `localize()` implementation so the error is self-containedlet ident = &derive_input.ident;quote! {impl #ident {fn localize(&self) -> String {unimplemented!("Encountered error in proc-macro")}}}}}; - edit in cli_macros/Cargo.toml at line 14
proc-macro-error = "1.0.4" - edit in cli_macros/Cargo.toml at line 18
wax = "0.6.0" - edit in Cargo.lock at line 34
"proc-macro-error", - replacement in Cargo.lock at line 37
"syn","syn 2.0.48","wax", - replacement in Cargo.lock at line 69
"syn","syn 2.0.48", - replacement in Cargo.lock at line 118
"syn","syn 2.0.48", - replacement in Cargo.lock at line 230
"syn","syn 2.0.48", - replacement in Cargo.lock at line 349
"syn","syn 2.0.48", - replacement in Cargo.lock at line 368
"syn","syn 2.0.48",][[package]]name = "proc-macro-error"version = "1.0.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"dependencies = ["proc-macro-error-attr","proc-macro2","quote","syn 1.0.109","version_check",][[package]]name = "proc-macro-error-attr"version = "1.0.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"dependencies = ["proc-macro2","quote","version_check", - replacement in Cargo.lock at line 468
"syn","syn 2.0.48", - edit in Cargo.lock at line 485
version = "1.0.109"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"dependencies = ["proc-macro2","unicode-ident",][[package]]name = "syn" - replacement in Cargo.lock at line 512
"syn","syn 2.0.48", - replacement in Cargo.lock at line 523
version = "1.0.56"version = "1.0.61" - replacement in Cargo.lock at line 525
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" - replacement in Cargo.lock at line 532
version = "1.0.56"version = "1.0.61" - replacement in Cargo.lock at line 534
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" - replacement in Cargo.lock at line 538
"syn","syn 2.0.48", - edit in Cargo.lock at line 568
[[package]]name = "version_check"version = "0.9.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - replacement in Cargo.lock at line 657
"syn","syn 2.0.48", - replacement in Cargo.lock at line 678
"syn","syn 2.0.48", - replacement in Cargo.lock at line 701
"syn","syn 2.0.48",