{"record":{"id":"2e269d175f45d613","repo":"tauri-apps/tauri","slug":"missing-cargo-pkg-name-environment-variable","errorCode":null,"errorMessage":"missing `CARGO_PKG_NAME` environment variable","messagePattern":"missing `CARGO_PKG_NAME` environment variable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-macros/src/command/wrapper.rs","lineNumber":237,"sourceCode":"                #diagnostic\n                trait AsyncCommandMustReturnResult {}\n                impl<A, B> AsyncCommandMustReturnResult for ::std::result::Result<A, B> {}\n                let _check: #return_type = unreachable!();\n                let _: &dyn AsyncCommandMustReturnResult = &_check;\n              };\n            };\n          } else {\n            return quote_spanned! {\n              span => compile_error!(\"async commands that contain references as inputs must return a `Result`\");\n            }.into();\n          }\n        }\n      }\n    }\n  }\n\n  let plugin_name = var(\"CARGO_PKG_NAME\")\n    .expect(\"missing `CARGO_PKG_NAME` environment variable\")\n    .strip_prefix(\"tauri-plugin-\")\n    .map(|name| quote!(::core::option::Option::Some(#name)))\n    .unwrap_or_else(|| quote!(::core::option::Option::None));\n\n  let body = match attrs.execution_context {\n    ExecutionContext::Async => body_async(&plugin_name, &function, &invoke, &attrs)\n      .unwrap_or_else(syn::Error::into_compile_error),\n    ExecutionContext::Blocking => body_blocking(&plugin_name, &function, &invoke, &attrs)\n      .unwrap_or_else(syn::Error::into_compile_error),\n  };\n\n  let Invoke {\n    message,\n    resolver,\n    acl,\n  } = invoke;\n\n  let root = attrs.root;","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-macros/src/command/wrapper.rs#L219-L255","documentation":"The tauri command wrapper macro reads the CARGO_PKG_NAME environment variable at compile time to detect whether the crate is a tauri-plugin-* package. It panics when the variable is absent, which should never happen in a normal cargo build since cargo always sets it.","triggerScenarios":"Compiling a crate that uses #[tauri::command] outside a normal cargo invocation — e.g. invoking rustc directly, or running the compiler in an environment where CARGO_PKG_NAME was stripped from the env.","commonSituations":"Custom build runners sanitizing environment variables, IDE tooling invoking rustc without cargo's env, sandboxed CI with restricted env, or exotic build orchestration.","solutions":["Build with cargo (or cargo build/test) so CARGO_PKG_NAME is set automatically","If using a custom runner, export CARGO_PKG_NAME=<crate-name> before compiling","Check sanitizer configs (env -i, docker -e filters, CI wrappers) that drop cargo-provided variables"],"exampleFix":"// before\nrustc --edition 2021 src/lib.rs   # no cargo env\n// after\ncargo build\n# or, if a custom runner is required:\nCARGO_PKG_NAME=my-crate rustc --edition 2021 src/lib.rs","handlingStrategy":"fallback","validationCode":"if std::env::var_os(\"CARGO_PKG_NAME\").is_none() {\n    panic!(\"build must run under cargo: CARGO_PKG_NAME missing\");\n}","typeGuard":null,"tryCatchPattern":"// set the var when a custom runner strips env\nif std::env::var_os(\"CARGO_PKG_NAME\").is_none() {\n    std::env::set_var(\"CARGO_PKG_NAME\", env!(\"CARGO_PKG_NAME\"));\n}","preventionTips":["Always build tauri crates through cargo, not bare rustc","Audit CI env sanitizers for dropped CARGO_* variables","Avoid `env -i` wrappers around build commands without re-exporting cargo vars"],"tags":["proc-macro","environment-variable","build","cargo"],"backgroundTag":"missing-env-var","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}