fix: Python bridge fallback only on missing venv, not script errors

The bridge.ts catch block was catching ALL errors from the venv Python
and falling back to system python3. This masked real script errors
(like rembg model loading failures) by reporting "rembg not installed"
from the system python3 fallback. Now only falls back on ENOENT (venv
binary not found).
This commit is contained in:
Siddharth Kumar Sah
2026-03-22 20:41:04 +08:00
parent 2bdc367767
commit 818d2acd94
+15 -2
View File
@@ -69,8 +69,21 @@ export async function runPythonScript(
execOpts,
);
return { stdout: stdout.trim(), stderr: stderr.trim() };
} catch {
// Try system python as fallback
} catch (venvError: unknown) {
// Only fall back to system python if the venv python binary doesn't exist
// (ENOENT). If the script itself failed, re-throw — don't hide the error.
const isNotFound =
venvError &&
typeof venvError === "object" &&
"code" in venvError &&
(venvError as { code?: string }).code === "ENOENT";
if (!isNotFound) {
const message = extractPythonError(venvError);
throw new Error(message);
}
// venv python not found — try system python3 as fallback
try {
const { stdout, stderr } = await execFileAsync(
"python3",