{"record":{"id":"fc6cc7339d4c6438","repo":"jely2002/youtube-dl-gui","slug":"unable-to-retrieve-platform-from-rust","errorCode":null,"errorMessage":"Unable to retrieve platform from Rust.","messagePattern":"Unable to retrieve platform from Rust\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/composables/usePlatform.ts","lineNumber":12,"sourceCode":"import { computed, onMounted, ref } from 'vue';\nimport { Platform } from '../tauri/types/app.ts';\nimport { invoke } from '@tauri-apps/api/core';\n\nexport function usePlatform() {\n  const platform = ref<Platform>(Platform.Unknown);\n\n  onMounted(async () => {\n    try {\n      platform.value = await invoke<Platform>('get_platform');\n    } catch (e) {\n      console.warn('Unable to retrieve platform from Rust.', e);\n    }\n  });\n\n  const isWindows = computed(() => platform.value === Platform.Windows);\n  const isMac = computed(() => platform.value === Platform.MacOS);\n\n  return { isWindows, isMac, platform };\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/jely2002/youtube-dl-gui/blob/c402ee39c0eabab68934c48f8b787ff37a1577b0/src/composables/usePlatform.ts#L1-L21","documentation":"usePlatform calls the Tauri command 'get_platform' on mount to determine the OS. If the invoke fails, the error is only logged with console.warn('Unable to retrieve platform from Rust.', e) — the ref stays Platform.Unknown and no exception propagates. This is a logged fallback, not a thrown error.","triggerScenarios":"invoke('get_platform') rejects because the command is not registered in the backend (missing tauri::command or generate_handler entry), the webview runs outside Tauri (plain browser/dev server), or the IPC bridge failed at startup.","commonSituations":"Running the frontend in a plain browser via vite dev without the Tauri shell; forgetting to register get_platform in the invoke_handler; calling usePlatform before the Tauri API is injected (SSR or early mount).","solutions":["Register the get_platform command in src-tauri's invoke_handler (tauri::generate_handler!).","Only rely on platform-specific behavior when platform !== Platform.Unknown; provide sensible defaults for Unknown.","If testing in a browser, mock get_platform or gate Tauri-only logic behind a 'running in Tauri' check.","Retry the invoke once on failure in case of an early IPC race."],"exampleFix":"// before\nplatform.value = await invoke<Platform>('get_platform');\n// after\nif ('__TAURI_INTERNALS__' in window) {\n  platform.value = await invoke<Platform>('get_platform');\n} else {\n  console.warn('Not running inside Tauri; platform stays Unknown');\n}","handlingStrategy":"fallback","validationCode":"const inTauri = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;\nif (!inTauri) console.warn('Not running in Tauri; platform unavailable');","typeGuard":"const isPlatformKnown = (p: Platform): boolean => p !== Platform.Unknown;","tryCatchPattern":"let platform = Platform.Unknown;\ntry {\n  platform = await invoke<Platform>('get_platform');\n} catch (e) {\n  console.warn('Unable to retrieve platform from Rust.', e);\n  platform = Platform.Unknown; // fallback; gate OS-specific features on this\n}","preventionTips":["Register get_platform in tauri::generate_handler! and test it after adding commands.","Gate platform-specific behavior behind platform !== Platform.Unknown.","Mock invoke in browser dev builds so missing IPC fails loudly."],"tags":["tauri","platform-detection","invoke","fallback"],"backgroundTag":"unsupported-platform","analyzedSha":"c402ee39c0eabab68934c48f8b787ff37a1577b0","analyzedAt":"2026-09-12T02:01:12.452Z","contentChangedAt":"2026-09-12T02:01:12.452Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}