zed-industries/zed · error · syn::Error

on_failure argument must be a string

Error message

on_failure argument must be a string

What it means

Returned while parsing the on_failure = ... argument of #[gpui::test] when its expression is not a string literal. The macro needs a literal function-name string to resolve the on-failure callback; any other expression type is rejected at that span.

Source

Thrown at crates/gpui_macros/src/test.rs:57

                    return Err(syn::Error::new(meta_path.span(), "unexpected path"));
                };
                ident.to_string()
            };

            match (&meta, ident.as_str()) {
                (Meta::NameValue(meta), "retries") => {
                    max_retries = parse_usize_from_expr(&meta.value)?
                }
                (Meta::NameValue(meta), "iterations") => {
                    max_iterations = parse_usize_from_expr(&meta.value)?
                }
                (Meta::NameValue(meta), "on_failure") => {
                    let Expr::Lit(ExprLit {
                        lit: Lit::Str(name),
                        ..
                    }) = &meta.value
                    else {
                        return Err(syn::Error::new(
                            meta.value.span(),
                            "on_failure argument must be a string",
                        ));
                    };
                    let segments = name
                        .value()
                        .split("::")
                        .map(|part| PathSegment::from(Ident::new(part, name.span())))
                        .collect();
                    let path = syn::Path {
                        leading_colon: None,
                        segments,
                    };
                    on_failure_fn_name = quote!(Some(#path));
                }
                (Meta::NameValue(meta), "seed") => {
                    seeds = vec![parse_usize_from_expr(&meta.value)? as u64]
                }

View on GitHub (pinned to f4178619ac)

Solutions

  1. Quote the function name: on_failure = "my_failure_handler"
  2. Define the named function in the same scope as the test
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui_macros/src/test.rs:57 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/b0cc4edc12eb1618. Report an issue: GitHub.