jely2002/youtube-dl-gui · warning
Unable to retrieve platform from Rust.
Error message
Unable to retrieve platform from Rust.
What it means
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.
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.
Example fix
// before
platform.value = await invoke<Platform>('get_platform');
// after
if ('__TAURI_INTERNALS__' in window) {
platform.value = await invoke<Platform>('get_platform');
} else {
console.warn('Not running inside Tauri; platform stays Unknown');
} Defensive patterns
Strategy: fallback
Validate before calling
const inTauri = typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;
if (!inTauri) console.warn('Not running in Tauri; platform unavailable'); Type guard
const isPlatformKnown = (p: Platform): boolean => p !== Platform.Unknown;
Try / catch
let platform = Platform.Unknown;
try {
platform = await invoke<Platform>('get_platform');
} catch (e) {
console.warn('Unable to retrieve platform from Rust.', e);
platform = Platform.Unknown; // fallback; gate OS-specific features on this
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
AI-assisted analysis of jely2002/youtube-dl-gui@c402ee39c0 (2026-09-12).
Data as JSON: /api/errors/fc6cc7339d4c6438.
Report an issue: GitHub.
Appendix: source
Thrown at src/composables/usePlatform.ts:12
import { computed, onMounted, ref } from 'vue';
import { Platform } from '../tauri/types/app.ts';
import { invoke } from '@tauri-apps/api/core';
export function usePlatform() {
const platform = ref<Platform>(Platform.Unknown);
onMounted(async () => {
try {
platform.value = await invoke<Platform>('get_platform');
} catch (e) {
console.warn('Unable to retrieve platform from Rust.', e);
}
});
const isWindows = computed(() => platform.value === Platform.Windows);
const isMac = computed(() => platform.value === Platform.MacOS);
return { isWindows, isMac, platform };
}
View on GitHub (pinned to c402ee39c0)