Skip to content

armgit / ente

Public Imported from GitHub
0

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

log.warn

Manav Rathif64d4943ed5f
diff --git a/desktop/src/main/log.ts b/desktop/src/main/log.ts
index 60870c913c..d1d65f8ae3 100644
--- a/desktop/src/main/log.ts
+++ b/desktop/src/main/log.ts
@@ -38,28 +38,32 @@ export const logToDisk = (message: string) => {
log.info(`[rndr] ${message}`);
};
-const logError = (message: string, e?: unknown) => {
- if (!e) {
- logError_(message);
- return;
- }
+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}\n${e.stack}`;
+ 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.
es = String(e);
}
- logError_(`${message}: ${es}`);
+ return `${message}: ${es}`;
};
-const logError_ = (message: string) => {
- log.error(`[main] [error] ${message}`);
- console.error(`[error] ${message}`);
+const logError = (message: string, e?: unknown) => {
+ const m = `[error] ${messageWithError(message, e)}`;
+ console.error(m);
+ log.error(`[main] ${m}`);
+};
+
+const logWarn = (message: string, e?: unknown) => {
+ const m = `[warn] ${messageWithError(message, e)}`;
+ console.error(m);
+ log.error(`[main] ${m}`);
};
const logInfo = (...params: unknown[]) => {
@@ -97,6 +101,11 @@ export default {
* console.
*/
error: logError,
+ /**
+ * Sibling of {@link error}, with the same parameters and behaviour, except
+ * it gets prefixed with a warning instead of an error tag.
+ */
+ warn: logWarn,
/**
* Log a message.
*
diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.ts
index f7d0436c0b..516fbe6dde 100644
--- a/desktop/src/main/services/upload.ts
+++ b/desktop/src/main/services/upload.ts
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { existsSync } from "original-fs";
import type { PendingUploads, ZipItem } from "../../types/ipc";
+import log from "../log";
import { uploadStatusStore } from "../stores/upload-status";
export const listZipItems = async (zipPath: string): Promise<ZipItem[]> => {
@@ -64,11 +65,16 @@ export const pendingUploads = async (): Promise<PendingUploads | undefined> => {
// file, but the dedup logic will kick in at that point so no harm will come
// of it.
if (allZipItems === undefined) {
- const allZipPaths = uploadStatusStore.get("filePaths") ?? [];
+ const allZipPaths = uploadStatusStore.get("zipPaths") ?? [];
const zipPaths = allZipPaths.filter((f) => existsSync(f));
zipItems = [];
- for (const zip of zipPaths)
- zipItems = zipItems.concat(await listZipItems(zip));
+ for (const zip of zipPaths) {
+ try {
+ zipItems = zipItems.concat(await listZipItems(zip));
+ } catch (e) {
+ log.error("Ignoring items in malformed zip", e);
+ }
+ }
} else {
zipItems = allZipItems.filter(([z]) => existsSync(z));
}