mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -69,8 +69,21 @@ export async function runPythonScript(
|
|||||||
execOpts,
|
execOpts,
|
||||||
);
|
);
|
||||||
return { stdout: stdout.trim(), stderr: stderr.trim() };
|
return { stdout: stdout.trim(), stderr: stderr.trim() };
|
||||||
} catch {
|
} catch (venvError: unknown) {
|
||||||
// Try system python as fallback
|
// 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 {
|
try {
|
||||||
const { stdout, stderr } = await execFileAsync(
|
const { stdout, stderr } = await execFileAsync(
|
||||||
"python3",
|
"python3",
|
||||||
|
|||||||
Reference in New Issue
Block a user