Skip to content

armgit / ente

Public Imported from GitHub
0

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

Generalize

Manav Rathi2a1b8ae18e1e
diff --git a/desktop/src/main/log-worker.ts b/desktop/src/main/log-worker.ts
index 042caa3804..7f0eb7a066 100644
--- a/desktop/src/main/log-worker.ts
+++ b/desktop/src/main/log-worker.ts
@@ -22,11 +22,10 @@
* expected to handle these (sending them to the actual log).
*/
export default {
- /**
- * Unlike the real {@link log.error}, this accepts only the first string
- * argument, not the second optional error one.
- */
- errorString: (s: string) => mainProcess("log.errorString", s),
+ error: (s: string, e?: unknown) =>
+ mainProcess("log.errorString", messageWithError(s, e)),
+ warn: (s: string, e?: unknown) =>
+ mainProcess("log.warnString", messageWithError(s, e)),
info: (...ms: unknown[]) => mainProcess("log.info", ms),
/**
* Unlike the real {@link log.debug}, this is (a) eagerly evaluated, and (b)
@@ -40,3 +39,21 @@ export default {
*/
const mainProcess = (method: string, param: unknown) =>
process.parentPort.postMessage({ method, p: param });
+
+// Duplicated verbatim from ./log.ts
+const messageWithError = (message: string, e?: unknown) => {
+ if (!e) return message;
+
+ let es: string;
+ if (e instanceof Error) {
+ // In practice, we expect ourselves to be called with Error objects, so
+ // this is the happy path so to say.
+ es = [`${e.name}: ${e.message}`, e.stack].filter((x) => x).join("\n");
+ } else {
+ // For the rest rare cases, use the default string serialization of e.
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
+ es = String(e);
+ }
+
+ return `${message}: ${es}`;
+};
diff --git a/desktop/src/main/log.ts b/desktop/src/main/log.ts
index e4a3029fc6..5e165da0fd 100644
--- a/desktop/src/main/log.ts
+++ b/desktop/src/main/log.ts
@@ -103,20 +103,26 @@ export const processUtilityProcessLogMessage = (
switch (m.method) {
case "log.errorString":
if (typeof p == "string") {
- log.error(`${logTag} ${p}`);
+ logError(`${logTag} ${p}`);
+ return true;
+ }
+ break;
+ case "log.warnString":
+ if (typeof p == "string") {
+ logWarn(`${logTag} ${p}`);
return true;
}
break;
case "log.info":
if (Array.isArray(p)) {
// Need to cast from any[] to unknown[]
- log.info(logTag, ...(p as unknown[]));
+ logInfo(logTag, ...(p as unknown[]));
return true;
}
break;
case "log.debugString":
if (typeof p == "string") {
- log.debug(() => `${logTag} ${p}`);
+ logDebug(() => `${logTag} ${p}`);
return true;
}
break;
diff --git a/desktop/src/main/services/ml-worker.ts b/desktop/src/main/services/ml-worker.ts
index 3397231fe7..8ce5deebc8 100644
--- a/desktop/src/main/services/ml-worker.ts
+++ b/desktop/src/main/services/ml-worker.ts
@@ -59,7 +59,7 @@ const parseInitData = (data: unknown) => {
) {
_userDataPath = data.userDataPath;
} else {
- log.errorString("Unparseable initialization data");
+ log.error("Unparseable initialization data");
}
};
@@ -127,7 +127,7 @@ const modelPathDownloadingIfNeeded = async (
} else {
const size = (await fs.stat(modelPath)).size;
if (size !== expectedByteSize) {
- log.errorString(
+ log.error(
`The size ${size} of model ${modelName} does not match the expected size, downloading again`,
);
await downloadModel(modelPath, modelName);