Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

debug strings

Manav Rathi81b52419a5b1
diff --git a/desktop/src/main/services/ml-util-test.ts b/desktop/src/main/services/ml-util-test.ts
index 9d312a4d04..18293c2a20 100644
--- a/desktop/src/main/services/ml-util-test.ts
+++ b/desktop/src/main/services/ml-util-test.ts
@@ -18,17 +18,23 @@ import { ensure, wait } from "../utils/common";
*/
const log = {
info: (...ms: unknown[]) => mainProcess("log.info", ms),
- debug: (fn: () => unknown) => console.log(fn()),
+ /**
+ * Unlike the real {@link log.debug}, this is (a) eagerly evaluated, and (b)
+ * accepts only strings.
+ */
+ debugString: (s: string) => mainProcess("log.debugString", s),
};
/**
* Send a message to the main process using a barebones protocol.
*/
-const mainProcess = (method: string, params: unknown[]) => {
- process.parentPort.postMessage({ method, params });
+const mainProcess = (method: string, param: unknown) => {
+ process.parentPort.postMessage({ method, param });
};
-log.debug(() => "Started ML worker process");
+log.debugString(
+ `Started ML worker process with args ${process.argv.join(" ")}`,
+);
process.parentPort.once("message", (e) => {
const port = ensure(e.ports[0]);
@@ -61,7 +67,7 @@ const handleMessageFromRenderer = async (m: unknown) => {
};
const foo = async (a: string) => {
- console.log("got message foo with argument", a);
+ log.info("got message foo with argument", a);
await wait(0);
return a.length;
};
diff --git a/desktop/src/main/services/ml.ts b/desktop/src/main/services/ml.ts
index 98eee821c6..5de35b4b28 100644
--- a/desktop/src/main/services/ml.ts
+++ b/desktop/src/main/services/ml.ts
@@ -96,20 +96,29 @@ export const createMLWorker = (window: BrowserWindow) => {
* we use the `parentPort` in the utility process.
*/
const handleMLWorkerRequests = (child: UtilityProcess) => {
+ const logTag = "[ml-worker]";
child.on("message", (m: unknown) => {
- if (m && typeof m == "object" && "method" in m && "params" in m) {
+ if (m && typeof m == "object" && "method" in m && "param" in m) {
+ const p = m.param;
switch (m.method) {
case "log.info":
- if (Array.isArray(m.params)) {
- const params = m.params as unknown[];
- log.info("[ml-worker]", ...params);
+ if (Array.isArray(p)) {
+ // Need to cast from any[] to unknown[]
+ log.info(logTag, ...(p as unknown[]));
return;
}
break;
+ case "log.debugString":
+ if (typeof p == "string") {
+ log.debug(() => `${logTag} ${p}`);
+ return;
+ }
+ break;
+
default:
break;
}
}
- log.warn("Ignoring unexpected message from ML worker", m);
+ log.info("Ignoring unexpected message from ML worker", m);
});
};