{"record":{"id":"07e6af003ab96506","repo":"tauri-apps/tauri","slug":"state-not-managed-for-field-on-command","errorCode":null,"errorMessage":"state not managed for field `{}` on command `{}`. You must call `.manage()` before using this command","messagePattern":"state not managed for field `(.+?)` on command `(.+?)`\\. You must call `\\.manage\\(\\)` before using this command","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/state.rs","lineNumber":63,"sourceCode":"}\n\nimpl<T: PartialEq> PartialEq for State<'_, T> {\n  fn eq(&self, other: &Self) -> bool {\n    self.0 == other.0\n  }\n}\n\nimpl<T: std::fmt::Debug> std::fmt::Debug for State<'_, T> {\n  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n    f.debug_tuple(\"State\").field(&self.0).finish()\n  }\n}\n\nimpl<'r, 'de: 'r, T: Send + Sync + 'static, R: Runtime> CommandArg<'de, R> for State<'r, T> {\n  /// Grabs the [`State`] from the [`CommandItem`]. This will never fail.\n  fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError> {\n    command.message.webview_ref().try_state().ok_or_else(|| {\n      InvokeError::from_anyhow(anyhow::anyhow!(\n        \"state not managed for field `{}` on command `{}`. You must call `.manage()` before using this command\",\n        command.key, command.name\n      ))\n    })\n  }\n}\n\n// Taken from: https://github.com/SergioBenitez/state/blob/556c1b94db8ce8427a0e72de7983ab5a9af4cc41/src/ident_hash.rs\n// This is a _super_ stupid hash. It just uses its input as the hash value. This\n// hash is meant to be used _only_ for \"prehashed\" values. In particular, we use\n// this so that hashing a TypeId is essentially a noop. This is because TypeIds\n// are already unique integers.\n#[derive(Default)]\nstruct IdentHash(u64);\n\nimpl std::hash::Hasher for IdentHash {\n  fn finish(&self) -> u64 {\n    self.0","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri/src/state.rs#L45-L81","documentation":"When an IPC command declares a `State<T>` parameter, Tauri extracts it from the managed state map. If `.manage(T)` was never called on the app builder for type T, from_command cannot find it and the invocation fails with this message naming the field and command.","triggerScenarios":"Invoking a command from the frontend whose signature includes `State<'_, MyType>` while `tauri::Builder::manage(MyType...)` was never called (or was called with a different type), during command argument deserialization.","commonSituations":"Forgetting `.manage()` in setup, managing the wrong concrete type (e.g. Mutex<Foo> vs Foo), state registered inside setup() after commands already invoked, or refactoring a command's state type without updating manage().","solutions":["Call `.manage(MyType::default())` (or your instance) on the tauri::Builder before `.run()`","Ensure the managed type exactly matches the command's State<T> generic (including wrappers like Mutex<T>)","If state must be created in setup, use `app.manage(...)` before the frontend can invoke commands"],"exampleFix":"// before\ntauri::Builder::default()\n  .invoke_handler(tauri::generate_handler![read_config])\n  .run(tauri::generate_context!())\n// after\ntauri::Builder::default()\n  .manage(AppConfig::default())\n  .invoke_handler(tauri::generate_handler![read_config])\n  .run(tauri::generate_context!())","handlingStrategy":"try-catch","validationCode":"// Rust: assert at startup that all state types are managed\nfn assert_managed(app: &tauri::App) {\n  assert!(app.state::<AppConfig>().inner() is ok: use app.try_state::<AppConfig>().is_some(), \"AppConfig not managed\");\n}","typeGuard":"fn managed<T: Send + Sync + 'static, R: tauri::Runtime>(cmd: &tauri::CommandItem<'_, R>) -> Option<tauri::State<'_, T>> {\n  cmd.message.webview_ref().try_state::<T>()\n}","tryCatchPattern":"// Frontend\ntry {\n  await invoke('read_config');\n} catch (e) {\n  if (String(e).includes('state not managed')) console.error('Call .manage(AppConfig::default()) in the builder');\n}","preventionTips":["Call .manage() for every type used in State<T> command params, right on the Builder chain","Keep managed types in one module and add a unit test invoking each command in setup_test","Match wrapper types exactly: State<Mutex<Foo>> needs .manage(Mutex<Foo>)"],"tags":["tauri","state","ipc","commands"],"backgroundTag":"missing-required-argument","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"}