tauri-apps/tauri · error · syn::Error

unexpected value for test

Error message

unexpected value for test

What it means

Compile-time syn::Error from the generate_context! macro parser: the `test` key in the tauri context invocation was given a value that is not a boolean literal. Only Lit::Bool is accepted for this option.

Solutions

  1. Use a plain boolean literal: test = true or test = false
  2. Enable test mode conditionally by choosing between two generate_context! invocations with #[cfg(...)] attributes instead
  3. Pass the string path argument directly if the goal was test mode (generate_context!("path", test = true))

Example fix

// before
tauri::generate_context!("tauri.conf.json", test = cfg!(debug_assertions))
// after
#[cfg(debug_assertions)]
const CONTEXT: tauri::Context = tauri::generate_context!("tauri.conf.json", test = true);
#[cfg(not(debug_assertions))]
const CONTEXT: tauri::Context = tauri::generate_context!("tauri.conf.json", test = false);
Defensive patterns

Strategy: validation

Validate before calling

// test must be a bare boolean literal
assert!(matches!(TEST_ATTR.as_str(), "true" | "false"), "test = <bool literal> only");

Prevention

When it happens

Trigger: Writing `test = 1`, `test = "true"`, `test = cfg!(debug_assertions)`, or any non-bool-literal value in a `generate_context!` invocation.

Common situations: Attempting to make test mode conditional via cfg! or env! macros; quoting the boolean as a string by mistake.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/0880ffd662fd7f34. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-macros/src/context.rs:106

              } else {
                return Err(syn::Error::new(
                  input.span(),
                  "unexpected value for capabilities",
                ));
              }
            }
            "assets" => {
              assets.replace(v.value);
            }
            "test" => {
              if let Expr::Lit(ExprLit {
                lit: Lit::Bool(LitBool { value, .. }),
                ..
              }) = v.value
              {
                test = value;
              } else {
                return Err(syn::Error::new(input.span(), "unexpected value for test"));
              }
            }
            name => {
              return Err(syn::Error::new(
                input.span(),
                format!("unknown attribute {name}"),
              ));
            }
          }
        }
        Meta::List(_) => {
          return Err(syn::Error::new(input.span(), "unexpected list input"));
        }
      }

      let _ = input.parse::<Token![,]>();
    }

View on GitHub (pinned to 460ec35447)