Return an error when user provides an exact path

finchie
Jul 3, 2024, 8:50 AM
RLX6XPNZKD6GIRLWKYXFH2RNIU4ZNXLMHXLOMID3E6H53QXXXNZQC

Dependencies

  • [2] VYPJUPPK Handle `GlobError::Build` in proc_macro error reporting
  • [3] D652S2N3 Rename `parse` module to `parse_fluent`
  • [4] 5FIVUZYF Unify `fluent_embed` macro API as `localize()`
  • [5] 5TEX4MNU Split `fluent_embed` into `group` and `parse` modules
  • [6] O77KA6C4 Create `fluent_embed` crate
  • [7] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [8] UOMQT7LT Add support for cardinal CLDR plural selectors
  • [9] NO3PDO7P Refactor `fluent_embed` to support structs
  • [10] V5S5K33A Add basic error handling for invalid paths in proc_macro attribute
  • [11] SHNZZSZG Create `cli_macros` shim crate
  • [*] VNSHGQYN Support using glob paths in `localize` macro
  • [*] UKFEFT6L Create basic `Output` proc-macro

Change contents

  • edit in fluent_embed/src/lib.rs at line 3
    [3.4284]
    [3.4284]
    use std::path::PathBuf;
  • edit in fluent_embed/src/lib.rs at line 13
    [3.1625]
    [3.1386]
    #[derive(thiserror::Error, Debug)]
    pub enum AttributeError {
    #[error("{0}")]
    Build(#[from] wax::BuildError),
    #[error("{0}")]
    Walk(#[from] wax::WalkError),
    #[error(":(")]
    NoMatches {
    path: PathBuf,
    complete_match: String,
    },
    }
  • replacement in fluent_embed/src/lib.rs at line 27
    [3.1387][3.0:87]()
    pub fn attribute_groups(path_literal: &syn::LitStr) -> Result<Group, wax::GlobError> {
    [3.1387]
    [3.4453]
    pub fn attribute_groups(path_literal: &syn::LitStr) -> Result<Group, AttributeError> {
  • replacement in fluent_embed/src/lib.rs at line 38
    [3.176][3.4883:4946](),[3.4883][3.4883:4946]()
    let captured_locale = entry.matched().get(1).unwrap();
    [3.176]
    [3.4946]
    let captured_locale = if let Some(captured) = entry.matched().get(1) {
    captured
    } else {
    return Err(AttributeError::NoMatches {
    path: entry.path().to_path_buf(),
    complete_match: entry.matched().complete().to_string(),
    });
    };
  • replacement in fluent_embed/src/lib.rs at line 63
    [3.299][3.299:342]()
    ) -> Result<TokenStream, wax::GlobError> {
    [3.299]
    [3.342]
    ) -> Result<TokenStream, AttributeError> {
  • edit in fluent_embed/Cargo.toml at line 16
    [3.1578]
    [13.892]
    thiserror = "1.0.61"
  • edit in cli_macros/src/lib.rs at line 3
    [3.131]
    [3.131]
    use fluent_embed::AttributeError;
  • edit in cli_macros/src/lib.rs at line 8
    [3.492][3.492:512]()
    use wax::GlobError;
  • replacement in cli_macros/src/lib.rs at line 18
    [3.791][3.791:820]()
    Err(glob_error) => {
    [3.791]
    [3.820]
    Err(attribute_error) => {
  • replacement in cli_macros/src/lib.rs at line 20
    [3.868][3.868:899](),[3.899][2.92:143]()
    match glob_error {
    GlobError::Build(build_error) => {
    [3.868]
    [2.143]
    match attribute_error {
    AttributeError::Build(build_error) => {
  • replacement in cli_macros/src/lib.rs at line 47
    [2.1576][3.958:1007](),[3.958][3.958:1007]()
    GlobError::Walk(walk_error) => {
    [2.1576]
    [3.1007]
    AttributeError::Walk(walk_error) => {
  • edit in cli_macros/src/lib.rs at line 66
    [3.1911]
    [3.1911]
    AttributeError::NoMatches {
    path,
    complete_match,
    } => {
    // Validate the assumption that the user has provided an exact path
    assert!(path.exists());
    assert_eq!(path.to_string_lossy(), complete_match);
    emit_error! { derive_attribute, "cannot match against an exact path";
    help = "The attribute should use glob syntax to match against multiple files";
    note = "For example, you can:\n{}\n{}",
    "- Match against directories: locale/**/errors.ftl",
    "- Match against files: locale/*.ftl";
    };
    }
  • edit in Cargo.lock at line 119
    [3.2433]
    [13.1952]
    "thiserror",