mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Register custom BiRefNet-matting ONNX session in install_feature.py so
rembg.new_session("birefnet-matting") no longer raises ValueError during
on-demand installs. The session was already registered in remove_bg.py
(runtime) and download_models.py (build-time) but was missed in the
install path, causing background-removal bundle installs to always fail.
Send JSON body on install/uninstall POST requests to avoid Fastify 5's
strict content-type parser rejecting body-less POSTs with 415.
Fix error message extraction to preserve structured {"error": ...} JSON
from the Python script and filter out pthread_setaffinity_np noise.
This commit is contained in:
@@ -202,9 +202,32 @@ export async function registerFeatureRoutes(app: FastifyInstance): Promise<void>
|
||||
duration_ms: Date.now() - installStartTime,
|
||||
});
|
||||
} else {
|
||||
const errorDetail =
|
||||
lastStderrLines.filter((l) => !l.startsWith("{")).join("\n") || stdoutBuffer.trim();
|
||||
const errorMsg = errorDetail || `Install failed with exit code ${code}`;
|
||||
// Extract the structured error from Python's fail() function first.
|
||||
// fail() writes {"error": "..."} to stderr — prefer this over raw lines.
|
||||
let errorMsg: string | undefined;
|
||||
for (let i = lastStderrLines.length - 1; i >= 0; i--) {
|
||||
const line = lastStderrLines[i];
|
||||
if (line.startsWith("{")) {
|
||||
try {
|
||||
const parsed = JSON.parse(line) as Record<string, unknown>;
|
||||
if (typeof parsed.error === "string") {
|
||||
errorMsg = parsed.error;
|
||||
break;
|
||||
}
|
||||
} catch {
|
||||
// Not valid JSON
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!errorMsg) {
|
||||
const meaningful = lastStderrLines.filter(
|
||||
(l) => !l.startsWith("{") && !l.includes("pthread_setaffinity_np"),
|
||||
);
|
||||
errorMsg =
|
||||
meaningful.join("\n") ||
|
||||
stdoutBuffer.trim() ||
|
||||
`Install failed with exit code ${code}`;
|
||||
}
|
||||
setInstallProgress(bundleId, null, errorMsg);
|
||||
updateSingleFileProgress({ jobId, phase: "failed", percent: 0, error: errorMsg });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user